-1

I have to find and replace a load of HTML which has a similar layout to this (I've left the formatting to demonstrate how it actually looks inline):

   <div  
     class="text-dark font-weight-normal mb-0 mt-0 item-card2-desc">
       <a href="javascript:void(0)"><i class="fa fa-map-signs"></i> Get
          Directions</a>
  </div>

I need to find and replace Get Directions with another string, let's say "Hello World" in VS Code. I've used RegExr to build this and validate it against the above but whilst it works on RegExr, VS Code finds no matches:

(Get)\s+(Directions)

Is there a VS Code format I've not applied?

Mark
  • 143,421
  • 24
  • 428
  • 436
Johnny John Boy
  • 3,009
  • 5
  • 26
  • 50
  • 2
    https://stackoverflow.com/questions/52647894/multiline-regular-expression-search-in-visual-studio-code "a regex search executes in multiline mode only if it contains a \n literal" – ceejayoz Apr 05 '23 at 20:31
  • Dang, I "fixed" the code formatting but that was bad, as it was necessary to show your problem. Sorry, please revert. [On the plus side, the quote in the above comment was from one of my answers...] – Mark Apr 20 '23 at 22:31
  • I re-edited, probably where it needs to be now. – Mark Apr 20 '23 at 23:25

1 Answers1

0

The problem here is that VS Code will search within the line, and in your example, Get and Directions are in different lines.

I tried (Get)[\s\n]+(Directions) and it worked. Just be aware that if you replace this, you will replace the line break as well.

Tomás Paim
  • 156
  • 4
  • VSC does not search within a line, It searches in the whole document text. According to MDN `\s` includes `\n` so `[\s\n]` is the same as `\s` – rioV8 Apr 05 '23 at 21:38
  • As stated in a comment to the question, VS Code will not search the whole document unless `\n` is present within the expression. https://stackoverflow.com/questions/52647894/multiline-regular-expression-search-in-visual-studio-code – Tomás Paim Apr 05 '23 at 21:45
  • but that means that VSC build on Electron build on Node uses a regex search that is not compliant with the doc on MDN, or is MDN a variant of the EcmaScript standard – rioV8 Apr 06 '23 at 06:54
  • 1
    @rioV8 VSCode has always needed an explicit `\n` to search across newlines. Or same with Ctrl+Enter in the find/search widget to enter a linebreak. – Mark Apr 11 '23 at 16:47