Search code examples
regexeditorvi

Find exact number pattern regex not working in Linux vi editor


I have a regex that finds the consecutive 15 numbers. It works fine in the notepad but when I try to run it on vi editor in Linux, it shows no pattern found. Even though there are numbers of the same length. Here is the regex I am using.

Regex: (?<!\d)\d{15}(?!\d) Any help will be appreciated.


Solution

  • Note that you need to do several things:

    • Add \v at the start to enable very magic mode to avoid over-escaping
    • Convert a (?<!\d) negative lookbehind to (\d)@<!
    • Convert a (?!\d) negative lookahead to (\d)@!
    \v(\d)@<!\d{15}(\d)@!