Reputation: 37098
I'm trying to solve a regex puzzle, and portions of the regexes keep consisting of pieces like this:
([^Xa-ehY]|[^f-zW])
or
([^2]|[^D-Za]|[D-Ze-f])
These confuse me.
Take the first one, for example: [^Xa-ehY]|[^f-zW])
. Doesn't this mean "not Xa-ehY OR not f-zW"? And doesn't that equate to "any character"? Take e
for example. It wouldn't match the first one, but it would match the second. W
would not match the second, but it would match the first.
Same with ([^2]|[^D-Za]|[D-Ze-f])
. This means "not 2 OR not D-Ze-f OR D-Ze-f", right? Which again amounts to "any character."
Am I missing something? Is this just a convoluted substitution for a single .
regex?
Upvotes: 4
Views: 84
Reputation: 405955
You can throw a bunch of text at them in a regex tester to see if any characters overlap. It's pretty crude, but your first example (\[^Xa-ehY\]|\[^f-zW\])
overlaps on the letter 'h'. The second example does look like it should match anything.
Upvotes: 1
Reputation: 10512
Since it is a puzzle you should look closer.
[^Xa-ehY]|[^f-zW]
is not the same as .
since they intersect at h
(f-z
contains h
) so it would be the same as [^h]
Upvotes: 1
Reputation: 24344
I think there are some characters that overlap. E.g. in the first on the lowercase h wouldn't match either side.
Admittedly the second one looks like it is just "."
Upvotes: 4