What is the meaning of these regular expressions?

I am trying to solve a regex puzzle, and the regex parts are made up of the following parts:

([^Xa-ehY]|[^f-zW])

or

([^2]|[^D-Za]|[D-Ze-f])

It bothers me.

Take the first one, for example: [^Xa-ehY]|[^f-zW]) . Doesn't that mean "not Xa-ehY OR not f-zW"? And doesn’t this correspond to "any character"? Take e , for example. This is not the first, but the second. W does not match the second, but matches the first.

Same thing with ([^2]|[^D-Za]|[D-Ze-f]) . This means "not 2 OR not D-Ze-f OR D-Ze-f", right? This again means "any character."

Am I missing something? Is this just a confusing substitution for one regex . ?

+4
source share
3 answers

I think some characters overlap. For instance. in the first lowercase h do not match on either side.

Admittedly, the second looks like this: "."

+4
source

Since this is a puzzle, you should look closer.

[^Xa-ehY]|[^f-zW] does not match . since they intersect in h ( fz contains h ), so it will be the same as [^h]

+1
source

You can throw a bunch of text in the regex test to see if any characters overlap. This is pretty rude, but your first example (\[^Xa-ehY\]|\[^f-zW\]) overlaps with the letter "h". The second example looks as if it should match something.

+1
source

All Articles