Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I search in Vim, using regular expressions for letters (both ascii and non ascii)?

Tags:

regex

vim

unicode

In .NET, \p{L} matches any ascii or non-ascii letter (so it will match both a and ü).

http://www.regular-expressions.info/unicode.html#prop

Is there a Vim equivalent for this?

In Vim \a or \w will only match characters in range [a-z] (or [0-9A-Za-z_]).

like image 346
frank Avatar asked Aug 22 '10 09:08

frank


People also ask

Does regex use Ascii?

The regular expression represents all printable ASCII characters. ASCII code is the numerical representation of all the characters and the ASCII table extends from char NUL (Null) to DEL . The printable characters extend from CODE 32 (SPACE) to CODE 126 (TILDE[~]) .

How do I match a character in regex?

To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ). E.g., \. matches "." ; regex \+ matches "+" ; and regex \( matches "(" . You also need to use regex \\ to match "\" (back-slash).


1 Answers

You can explicitly tell vim which ranges of hex values to match. This is kind of a shotgun approach, but if you know what the possible ranges (like UTF-8 for example) this would work:

/[\x7f-\xffa-zA-Z]

You can also search for explicit unicode values by entering in the unicode character directly or it's code in the following format:

/\%u0300
like image 187
Brian Clements Avatar answered Sep 20 '22 15:09

Brian Clements