1

I am trying to write a regular expression that will match a link-attribute in .png files.

Example: I have a lot of .png like this

https://jnTb6EZom8c/s144/800px-s%25252Ct%252529%2520%25282%2529.png
https://jnTb6EZom8c/s1300/800px-s%25252Ct%252529%2520%25282%2529.png
https://jnTb6EZom8c/s50/800px-s%25252Ct%252529%2520%25282%2529.png

I want to search for /s144 /s1300 /s50 and so on and replace it with /s400+c. My Regex /\/s\B\d{2,4}/ works fine in Regex-Tester.

Now I want to do the job with vim, but I always get 'pattern not found'. What is wrong with my regular-expression?

3

There's a few problems with your version. / needs to be backslash escaped in the Vim find command line*, and {2,4} type repeats also need a preceding backslash. The \B zero-width non-word boundary atom does not exist in Vim-flavour regular expressions, but I don't think it's actually required for your purpose, anyway.

Try /\/s\d\{2,4}/

See :help pattern-overview for details of Vim's regular expressions.

* Note that in other contexts, such as in an :s command, you can use almost any non-alphanumeric character as a regular expression delimiter. If you want to include / characters in your expression, just use a different character for your delimiter.

  • /\/s\d{2,4}/is not working for me, but /\/s\d\{2,4}/ works fine! Thanks for help. – oliver Feb 21 '15 at 12:14
  • You're right! I've updated my answer. – Rich Feb 21 '15 at 16:46

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.