Regex to first occurrence only? [duplicate]

The regex is greedy meaning it will capture as many characters as it can which fall into the .* match. To make it non-greedy try:

this(.*?)test

The ? modifier will make it capture as few characters as possible in the match.

Leave a Comment