I'm trying to extract the first jpg from a page of text. multiple paragraphs and multiple urls in each, but i only want the first url/jpg, stop after first is matched/returned.
sample page;
this is some text and a url src="https://www.someurl.jpg" more text, more text, more text. more text, more text
more text, more text. this is some text and a url src="https://www.anotherurl.jpg" more text, more text, more text. more text, more text.
Current Code;
(?<=src=")(.*?)(?=")
This code returns both urls. I need the output to be just the first one it finds and stop there, just return the first.
Output required;
any help appreciated.
Your regex is quite good, just add surroundings and g flag. /(?<=src=")(.*?)(?=")/g Now You gave correct regex.
You can read here about regexp flags.