F
Fiaz Idris
Keywords: Character Class Regex Regular Expression Regular Expressions \W_ \W
I know that [\W] matches [^a-zA-Z_0-9]
From Mastering Algorithms with Perl (Page.110), I see a character class
[\W_] that does the following
s/[\W_]+//g
i.e. to replace (all non-word character and underscore) with (nothing).
First, I couldn't understand the above that is because I interpreted
above regex as *** replace "\W" with "^a-zA-Z_0-9" ***
s/[^a-zA-Z_0-9_]+//g -------------->(regex XXX)
That is to replace (non-word characters including underscore) with (nothing)
and thought that the last underscore is infact unnecessary.
My question is where in the documentation (anywhere) that says
the [\W] will infact work with the interpretation as below:
[~`!@#$%^&*()-[]:;<,./"? ........and so on] but not the interpretation
give in (regex XXX) above.
If this seems to be a dumb question, I apologise. But, still I require
an explanation.
I know that [\W] matches [^a-zA-Z_0-9]
From Mastering Algorithms with Perl (Page.110), I see a character class
[\W_] that does the following
s/[\W_]+//g
i.e. to replace (all non-word character and underscore) with (nothing).
First, I couldn't understand the above that is because I interpreted
above regex as *** replace "\W" with "^a-zA-Z_0-9" ***
s/[^a-zA-Z_0-9_]+//g -------------->(regex XXX)
That is to replace (non-word characters including underscore) with (nothing)
and thought that the last underscore is infact unnecessary.
My question is where in the documentation (anywhere) that says
the [\W] will infact work with the interpretation as below:
[~`!@#$%^&*()-[]:;<,./"? ........and so on] but not the interpretation
give in (regex XXX) above.
If this seems to be a dumb question, I apologise. But, still I require
an explanation.