const regex = /\/o\/([a-zA-Z0-9]+)\/([a-zA-Z0-9-]+)/gi;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\\/o\\\/([a-zA-Z0-9]+)\\\/([a-zA-Z0-9-]+)', 'gi')
const str = `https://firebasestorage.googleapis.com/v0/b/geographical-memories-dev.appspot.com/o/Fa4NPIoM5sON70uDJjufgnL5DHY2/01792dcc-4963-4658-a3d0-99073b352e22?alt=media&token=23676a66-ed8d-4b43-9150-6ef3f07544f0
https://firebasestorage.googleapis.com/v0/b/geographical-memories-dev.appspot.com/o/Fa4NPIoM5sON70uDJjufgnL5DHY2/01792dcc-4963-4658-a3d0-99073b352e22?alt=media&token=80a5cc0f-7943-4ef8-ab00-9bef8acd41bf`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions