Go (RE2)

Non-Capturing Group (Image URL) in GO

Use non-capturing groups `(?:...)` to alternate without polluting the captured-groups list.

Try it in the GO tester →

Pattern

regexGO
(?:https?:\/\/)\S+\.(?:jpg|jpeg|png|gif|webp|svg)   (flags: gi)

Go (RE2) code

goGo
package main

import (
	"fmt"
	"regexp"
)

func main() {
	re := regexp.MustCompile(`(?i)(?:https?:\/\/)\S+\.(?:jpg|jpeg|png|gif|webp|svg)`)
	input := `Logo at https://example.com/logo.png and https://cdn.io/img.svg`
	for _, match := range re.FindAllString(input, -1) {
		fmt.Println(match)
	}
}

Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.

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

Matches

  • https://example.com/logo.png
  • https://cdn.io/img.svg

Input

http://insecure.test/photo.JPEG

Matches

  • http://insecure.test/photo.JPEG

Input

ftp://old/asset.png

No match

Same pattern, other engines

← Back to Non-Capturing Group (Image URL) overview (all engines)