const regex = /(?:https:\/\/goo\.gl\/maps\/\w+)|(?:https:\/\/www\.google\.com\/maps[^ ]*\d)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?:https:\\\/\\\/goo\\.gl\\\/maps\\\/\\w+)|(?:https:\\\/\\\/www\\.google\\.com\\\/maps[^ ]*\\d)', 'gm')
const str = `https://goo.gl/maps/WwcXqVEA5vrEWFtAA
follow this link https://goo.gl/maps/rob6c2k27E4ZpiDd8
https://goo.gl/maps/efNxki1ek7RZ3CAFA need to check in google maps
https://www.google.com/maps/@-6.2964394,107.1813443,3a,75y,90t/data=!3m8!1e2!3m6!1sAF1QipNrLqMTMz-iqWjqvmedTHyQwGLhBE-Z0L46Z5mY!2e10!3e12!6shttps:%2F%2Flh5.googleusercontent.com%2Fp%2FAF1QipNrLqMTMz-iqWjqvmedTHyQwGLhBE-Z0L46Z5mY%3Dw203-h152-k-no!7i1000!8i750 is correct?
https://www.google.com/maps/place/Jl.+Raya+Rw.+Bangkong,+Sertajaya,+Kec.+Cikarang+Tim.,+Bekasi,+Jawa+Barat+17530/@-6.2971014,107.184237,19z/data=!3m1!4b1!4m5!3m4!1s0x2e699b50084e936d:0xc3f7ba2bef9eafc8!8m2!3d-6.2971641!4d107.1847831 how about this? 1234
https://google.com/maps/place/Jl.+Raya+Rw.+Bangkong,+Sertajaya,+Kec.+Cikarang+Tim.,+Bekasi,+Jawa+Barat+17530/@-6.2971014,107.184237,19z/data=!3m1!4b1!4m5!3m4!1s0x2e699b50084e936d:0xc3f7ba2bef9eafc8!8m2!3d-6.2971641!4d107.1847831 how about this? 1234`;
// 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