All Collections
Knowledge Base
Developers: Extract shortId from tour URL
Developers: Extract shortId from tour URL

When integrating CloudPano with you app, you may sometimes need to extract the tour id, what we call the shortId, from the URL.

Clayton Rothschild avatar
Written by Clayton Rothschild
Updated over a week ago

Here's a regular expression that can extract the shortId from the URL of a tour or project hosted on CloudPano:

javascript

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: DEMO

Explanation 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:

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: DEMO

Explanation 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.

Did this answer your question?