2

I am having a hard time understanding this "magic" thing in Vim.

Currently I am making a very simple regex search to get last list of numbers in a string:

    for file in files
        echo file
        let versionNum = matchstr(file, '(\d+)(?!.*\d)')
    end for

Something like that in above. Basically if a string is: xxx.xxx.xxx.x1234 I should only parse out 1234.

However, I am having hard time using a regex expression in matchstr and a bit of google searching weren't enough to make me fully understand what I am doing wrong here.

PBJ
  • 65
  • 4

1 Answers1

3

You need to use \v at the start of your pattern to explicitly require to work in magic mode.

Also, the syntax you're using isn't supported by vim. While not perfect, I'd use: \v.*\D\zs\d+|^\d+, or more simply: \v\d+\ze\D*$.

Luc Hermitte
  • 31,979
  • 7
  • 69
  • 83