Find multiple urls with regex

Viewed 292

I need to find multiple urls within a string. The regex I'm using is

(https?:\/\/.*\.(?:png|jpg))

and the string is Newhttps://www.findregexhere.com/newimage.pngfrhttps://www.findregexhere.com/newimage.pngnewimage

Here is the code I am using

let regex = try NSRegularExpression(pattern: "https?:\/\/.*\.(?:png|jpg)$", options: .caseInsensitive)
let nsString = text as NSString
let results = regex.matches(in: text, range: NSRange(location: 0, length: nsString.length))

but the result is giving me this

https://www.findregexhere.com/newimage.pngfrhttps://www.findregexhere.com/newimage.png

1 Answers
Related