0

From a previous question I have this nice regular expression:

\[.*\]\((?!http)(?!.+\.md).+\)

It matches all internal Markdown links that do not have a .md file extension. You can see some matches of it here: https://regex101.com/r/0uW1cl/6

This regex works just fine in an opened file via Edit -> Find (or Ctrl + F) when I enable "Use Regular Expression" in the find input field.

enter image description here

But it does not work in the Edit -> Find in Files functionality:

regex does not work in the Edit -> Find in Files functionality

As you can see on the screenshot it gives me this nice error message:

Error parsing regex near `]\((?!http' at character offset 9: Unrecognized flag: '!'. (Allowed flags: i, m, s, U, u, x.) Blockquote

As far as I know those use the same code behind the scenes to execute regular expression searches.

Why does it work in "Find", but not "Find in Files"?
Is there a way to fix this or a workaround?

(For now I am using Notepad++ which seems to handle this regex fine, but of course I would prefer to keep working in VS Code)

janpio
  • 10,645
  • 16
  • 64
  • 107

1 Answers1

0

As far as I know those use the same code behind the scenes to execute regular expression searches.

Yeah, I shouldn't assume things like that:

  • Rust Regex in the Find/Replace in Files Sidebar
  • JavaScript Regex in the Find/Replace in File Widget

via https://stackoverflow.com/a/42184299/252627

And Rust Regex can not handle negative lookaheads as it doesn't support lookaround at all:

Its syntax is similar to Perl-style regular expressions, but lacks a few features like look around and backreferences. In exchange, all searches execute in linear time with respect to the size of the regular expression and search text.

https://doc.rust-lang.org/regex/regex/index.html

janpio
  • 10,645
  • 16
  • 64
  • 107