0

This regex performed on "waswas" returns the entire string unless I make it "waspwas".

w[^p]*s

How can I make this regex return two separate matches?

ethtrhaef
  • 37
  • 5
  • Not trying to be snide, but you can't make that regex make two separate matches; you need a different regex if you want that. But what is it supposed to do? Can you describe in English what pattern should match? Do you want w, followed by any characters EXCEPT s or p, then an s? – Howlium Aug 12 '20 at 04:50
  • If you just want the shortest match, then this seems like a duplicate of Greedy vs. Reluctant vs. Possessive Quantifiers (https://stackoverflow.com/questions/5319840/greedy-vs-reluctant-vs-possessive-quantifiers/5319978#5319978). – Howlium Aug 12 '20 at 04:52
  • See [Greedy vs. Reluctant vs. Possessive Quantifiers](https://stackoverflow.com/questions/5319840/greedy-vs-reluctant-vs-possessive-quantifiers/5319978#5319978). – Howlium Aug 12 '20 at 04:53

1 Answers1

1

If you want w as a break point, you need to exclude it from matching in the middle.

w[^pw]*s
Tomalak
  • 306,836
  • 62
  • 485
  • 598