I'm trying to use a regex for searching in a file. I noticed
that inside square brackets \w seems to loose all magical
matching abilities. Is there a way to reverse that loss or do
I have to specify everything inside [] explicitly?
For the below examples, I'll assume you want an "at-sign" added
to the set just so it's obvious where the change takes
place...modify accordingly.
Yes, the "\w" loses its meaning inside a [] set (unlike Python's
regexps, which threw me when I first came across this difference).
You can either do it explicitly:
[EMAIL PROTECTED]
or you can do it explicitly using Posix notation:
[[:alnum:[EMAIL PROTECTED]
or you can use branching:
\%(\w\|@\)
I'm sure there are even more ways to go about this. As you
mention wanting to target filenames, there's actually a section
of text after
:help [:alnum:]
where it says
For example, the following is a plausible pattern
for a UNIX filename: "[-./[:alnum:]_~]\+"
That is, a list of at least one character, each of
which is either '-', '.', '/', alphabetic, numeric,
'_' or '~'.
These items only work for 8-bit characters.
So some of the dirty work has already been done for you :)
HTH,
-tim