Reputation: 2147
I'm trying to write a RegEx that matches a string under three conditions:
1) The whole string matches all or some of the capture groups defined in pattern
2) Capture groups do not have to be defined in the same order they appear in the pattern
3) Pattern can have an unknown number of capture groups that are NOT found in string
So some RegEx that includes the following capture groups...
(,101,)|(,10,)|(,203,)|(,542,)
I would expect the RegEx to match the following...
,203,10,101,
...because every bit of the string is somehow matched.
But I would NOT want it to match this string...
,203,684,10,
...because ,684, was not one of the groups specified.
This will be eventually fed into an SQL statement. So I could potentially do the exact opposite of what I've stated and then make my SQL query NOT REGEX. So essentially a double negative.
Upvotes: 0
Views: 978
Reputation: 8323
So... is this what you are looking for?
/^,(101,|10,|203,|542,)+$/
Upvotes: 1