Non-Capturing Group (Image URL) in JS
Use non-capturing groups `(?:...)` to alternate without polluting the captured-groups list.
Try it in the JS tester →Pattern
regexJS
(?:https?:\/\/)\S+\.(?:jpg|jpeg|png|gif|webp|svg) (flags: gi)JavaScript / ECMAScript code
jsJavaScript
const re = new RegExp("(?:https?:\\/\\/)\\S+\\.(?:jpg|jpeg|png|gif|webp|svg)", "gi");
const input = "Logo at https://example.com/logo.png and https://cdn.io/img.svg";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
How the pattern works
(?:https?:\/\/) groups the protocol options without capturing them — useful when you only care about matching, not extracting. \S+ matches the non-whitespace URL body. \.(?:jpg|jpeg|png|gif|webp|svg) matches the dot and extension via another non-capturing group. The pattern has zero capture groups; switch to `(...)` if you need to extract pieces.
Examples
Input
Logo at https://example.com/logo.png and https://cdn.io/img.svgMatches
https://example.com/logo.pnghttps://cdn.io/img.svg
Input
http://insecure.test/photo.JPEGMatches
http://insecure.test/photo.JPEG
Input
ftp://old/asset.pngNo match
—