0

I'm trying to match a particular path pattern for an autocommand. I have this:

au BufRead *.md if expand('<amatch>') =~ "/path/to/dir/[0-9]" 

It successfully matches, eg.

c:\soemthing-or-other\path\to\dir\790-798-testing\790-798-testing.md

However, I cannot better refine the match: eg,

au BufRead *.md if expand('<amatch>') =~ "/path/to/dir/[0-9]\{2\}"
au BufRead *.md if expand('<amatch>') =~ "/path/to/dir/[0-9]*\.md$"
au BufRead *.md if expand('<amatch>') =~ "/path/to/dir/\d*\.md$"
au BufRead *.md if expand('<amatch>') =~ "/path/to/dir/\d"

All of the above fail. Why? What am I doing wrong? Is there something about regex patterns in autocommands I'm missing?

4
  • 1
    try using single quotation (or double the backslashes) Commented Jun 24, 2021 at 10:11
  • Wow! Thanks very much. Single quoting the pattern makes it all come good. Question is, why some patterns work with double quotes, eg /testing/[0-9] and /testing/[:digit:], but most others don't?
    – Tom
    Commented Jun 25, 2021 at 3:17
  • Hi Tom—if you have more questions, you should ask them as questions. The answer section is for answers. I’m going to convert this whole thing to a comment for now; if you want to add an answer or ask a new question, please do.
    – D. Ben Knoble
    Commented Jun 25, 2021 at 11:17
  • @Tom this is explained I believe at :h expr-quote and :h literal-string Commented Jun 25, 2021 at 11:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.