3

This page says that I can find duplicate words using a regular expression.

The suggested command is

\(\<\w\+\>\)\_s*\<\1\>

What does "\w" mean here? Suppose the target pattern is "123\t123" where \t is the tab. Would the command be

/\(\<\1\+\>\)\t\<\1\>

or

/\(\<1\+\>\)\t\<\1\>
5

:help /\w shows that \w is a regex metacharacter matching a word character -- any character that is either an underscore (_) or in the ranges 0-9, a-z, or A-Z.

The example regex is parsed as

\(        \)                Capture the match so it can be reused later
  \<    \>      \<  \>      Match (with zero-width) beginning/end of word
    \w\+                    Match one or more word characters
            \_s*            Match zero or more whitespace characters,
                              including newlines
                  \1        Match the same text as the first capture

This style of search is useful when you don't exactly know the contents of whatever is going to match inside the \( \).

Assuming that there's more possible variety in your suggested text to match (any 3-digit number, rather than just 123), you could use the style of regex as follows

\(\d\d\d\)\t\1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.