Hi,

Thomas Michael Engelke wrote:
> 
> 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?

yes, inside [] backslashes don't start a character class but may only be
used to denote special characters:

  \e    <Esc>
  \t    <Tab>
  \r    <CR>    (NOT end-of-line!)
  \b    <BS>
  \n    line break, see above |/[\n]|
  \d123 decimal number of character
  \o40  octal number of character up to 0377
  \x20  hexadecimal number of character up to 0xff
  \u20AC        hex. number of multibyte character up to 0xffff
  \U1234        hex. number of multibyte character up to 0xffffffff

There is a different notation to denote character classes inside brackets:

  [:alnum:]     letters and digits
  [:alpha:]     letters
  [:blank:]     space and tab characters
  [:cntrl:]     control characters
  [:digit:]     decimal digits
  [:graph:]     printable characters excluding space
  [:lower:]     lowercase letters (all letters when
                'ignorecase' is used)
  [:print:]     printable characters including space
  [:punct:]     punctuation characters
  [:space:]     whitespace characters
  [:upper:]     uppercase letters (all letters when
                'ignorecase' is used)
  [:xdigit:]    hexadecimal digits
  [:return:]    the <CR> character
  [:tab:]       the <Tab> character
  [:escape:]    the <Esc> character
  [:backspace:] the <BS> character

So instead of [\w] you should use [[:alpha:]] (note the double
brackets).

You can find more on brackets in regular expressions with

  :help /[]

Regards,
Jürgen

-- 
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us.     (Calvin)

Reply via email to