question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Global regex search with "Not matching character" doesn't match newline

See original GitHub issue

Issue Type: Bug

I was trying to search for

Promise\.all\(\[[^\]]*await[^\]]*\]\)

but I had no way to turn on multiline support so that ^\] would match newlines too. So searching for below would not be found.

return await Promise.all([
  await this.someFunction1(),
  await this.someFunction2(),
]);

I later put in the below and was happy to find that it suddely worked, but knew that it would only find if await was on the first line after the bracket, and also if there was no chars other than newline space or tab.

Promise\.all\(\[[^\]]*[\n\r \t]await[^\]]*\]\)

But, I then started to find others that actually SHOULDN’T have worked… It was at this point, I realsed that ^\] was working as expected the first time, and was matching on newline chars… (Perfect, I removed my tab/space hack)… To find, it stopped working again…

It seems I need atleast 1 \n in the regex to make it work.

My quick fix was to add this at the very end as such

Promise\.all\(\[[^\]]*await[^\]]*\]\)\n{0}

But this is obviously a dirty hack and not an obvious one, be far better to test for Not Matching and turn multiline back on, similar to what ever test you are doing for searching for \n and turning on multiline

VS Code version: Code 1.35.0 (553cfb2c2205db5f15f3ee8395bbd5cf066d357d, 2019-06-04T01:17:12.481Z) OS version: Windows_NT x64 10.0.10240

System Info
Item Value
CPUs Intel® Xeon® CPU E5-1620 v3 @ 3.50GHz (8 x 3492)
GPU Status 2d_canvas: enabled
checker_imaging: disabled_off
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
rasterization: enabled
surface_synchronization: enabled_on
video_decode: enabled
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 15.92GB (5.33GB free)
Process Argv
Screen Reader no
VM 0%
Extensions (19)
Extension Author (truncated) Version
markdown-preview-github-styles bie 0.1.6
npm-intellisense chr 1.3.0
ssh chr 0.0.4
vue-peek dar 1.0.2
vscode-eslint dba 1.9.0
vscode-ts-auto-return-type ebr 1.0.1
tslint eg2 1.0.43
RunOnSave eme 0.0.18
prettier-vscode esb 1.9.0
todo-tree Gru 0.0.134
node-module-intellisense lei 1.5.0
camelcasenavigation map 1.0.1
rainbow-csv mec 1.1.1
node-modules-resolve nau 1.0.2
uuid-generator net 0.0.4
vetur oct 0.21.0
gitconfig sid 2.0.0
open-in-browser tec 2.0.0
sort-lines Tyr 1.8.0

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:7
  • Comments:22 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
WORMSScommented, Nov 29, 2022

I just use \n{0} a the end of all my searches… been working fine so far…

1reaction
WORMSScommented, Jul 11, 2019

Then 👍 Big thumbs up that [^s] should indeed turn that mode on… Ok… I am up to date and agreeing. Good job everyone… take a 5 minute break and enjoy your evening.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Regular expression to match a line that doesn't contain a word
The notion that regex doesn't support inverse matching is not entirely true. You can mimic this behavior by using negative look-arounds: ^((?!hede).)*$.
Read more >
Searching - Notepad++ User Manual
Selecting Search Mode of Regular expression will cause the Match whole word only option to become unchecked and disabled (greyed out). A possible...
Read more >
Regex Tutorial - The Dot Matches (Almost) Any Character
In all regex flavors discussed in this tutorial, the dot does not match line ... In EditPad Pro, turn on the “Dot” or...
Read more >
Regular expressions - JavaScript - MDN Web Docs
Generate indices for substring matches. ... Global search. ... Case-insensitive search. ... Allows ^ and $ to match newline characters. ... Allows ....
Read more >
Regex Line Break - Videozin
+: matches one or more of the preceding token – in. The Apache OpenOffice regular expression behavior when matching paragraph marks and newline...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found