I was seeing some regular expressions here on the network, and I noticed that in many, in the character field, .
was not escaped \.
. Thus: [a-zA-Z0-9.]
.
It does not need the \
character before, does it?
I was seeing some regular expressions here on the network, and I noticed that in many, in the character field, .
was not escaped \.
. Thus: [a-zA-Z0-9.]
.
It does not need the \
character before, does it?
No, because it would not make sense to allow "any character" inside brackets. Consider the given example. If the point inside the bracket is special, the expression:
[a-zA-Z0-9.]
would be equivalent to simply:
.
(i.e. both match "any one character")
Since there is no sense to use this way, the .
within the bracket is considered a point, and therefore does not have to be "escaped."
Have different meanings .
can be any character, since \.
is understood as the dot character.
But you should note the expression context , in which case it is concatenating the ranges from az, AZ, 0-9 and also accepts the dot character.