Reputation: 49237
I have this string:
of cabbages and kings and more kings
I want to match based on this criteria:
- Any instance of "king"
- Any instances of "cab" OR "goat"
- No instances of "bill"
This regex works for IsMatch():
^(?=.*?(king))(?=.*?(cab|goat))(?=.*?(bill))
But it just returns 1 group with a 0 length. Is there a way to have it return matching groups so that we can read the matched text after?
Upvotes: 1
Views: 78
Reputation: 32787
Because your pattern use only lookarounds,it would only check for the pattern but would never include the matched pattern except any groups in lookarounds..
If you want to capture the complete string,use the Match
method with the given pattern
^(?=.*king)(?=.*(?:cab|goat))(?=.*bill).*$
This regex would match the complete string in group 0 if it matches the pattern..
Upvotes: 1