I need a regex that matches first “xyz” and all characters that come before. For example, for
“abxyzcdxyz” it should match “abxyz”. I was trying with pattern “.*xyz”, but it matches the entire string.
I need a regex that matches first xyz and all characters that come before.
Share
Try non-greedy matching:
*?is a non-greedy quantifier, i.e. it matches zero or more occurrences, but as few as possible.