Here's a regular expression that can extract the shortId from the URL of a tour or project hosted on CloudPano:
const url = 'https://app.cloudpano.com/tours/DEMO?sceneId=sdsjdkil';
const regex = /\/tours\/([^?/]+)/;
const match = url.match(regex);
const shortId = match ? match[1] : null;
console.log(shortId); // Output: DEMOExplanation of the regular expression /\/tours\/([^?/]+)/:
- \/tours\/: Matches the literal string "/tours/".
- ([^?/]+): Matches and captures one or more characters that are not a forward slash (/) or a question mark (?). The captured part represents the shortId.
Now, here's an example in PHP:
$url = 'https://app.cloudpano.com/tours/DEMO?sceneId=sdsjdkil';
$regex = '/\/tours\/([^?\/]+)/';
preg_match($regex, $url, $matches);
$shortId = isset($matches[1]) ? $matches[1] : null;
echo $shortId; // Output: DEMOExplanation of the regular expression '/\/tours\/([^?\/]+)/':
- \/tours\/: Matches the literal string "/tours/".
- ([^?\/]+): Matches and captures one or more characters that are not a forward slash (/) or a question mark (?). The captured part represents the shortId.
Note that in PHP, you need to use forward slashes (/) as the delimiters for the regular expression. Also, preg_match is used to perform the regular expression match and populate the $matches array with the captured groups.
