Reputation: 2865
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.
Upvotes: 1
Views: 244
Reputation: 545618
Try non-greedy matching:
.*?xyz
*?
is a non-greedy quantifier, i.e. it matches zero or more occurrences, but as few as possible.
Upvotes: 5