7

For example, I have the following lines:

//sys.log(siteNameToPrepare);
 //sys.log(siteNameToPrepare);
        // sys.log("downloadFolder: "+downloadFolder);
 // lorem ipsum ...
 arbitrary codes here...
 var a = _POST;
 sys.log("groupManagementHandler.jhp _POST is not object");
sys.log("groupManagementHandler.jhp _POST is not object");

I only want to match sys.log(xxx) that is not commented out. I tried to use the following regex:

[^/ ]sys.log

on the search bar (Ctrl+Shift+F), with Regex ON, to find the uncommented sys.log within files of a folder.

enter image description here

It matches uncommented lines in several files, however, I missed some lines that has couple of whitespaces in front of sys.log.

My question is how to match those lines? What am I missing here?

Seems like I couldn't find the answer in Google and Stackoverflow, I found this one, but this one is for Visual Studio, not Visual Studio Code. Visual Studio Search Uncommented Code

Here's the error message I got by using the look ahead pattern: enter image description here

Thanks to @Wiktor Stribiżew, now I can confirm that the regex lookahead pattern for searching within files works in older Visual Studio Code (V1.2.0) but not works in Version 1.17.1.

So this question may somehow can be seen as a duplicated question due to the bug of newer version VS code, that led me to post this question.

Artan
  • 91
  • 1
  • 1
  • 9
  • Question for you: Are the commented out calls to `sys.log` always immediately preceded by `//`? Is there any pattern to the way the lines are commented out? – Tim Biegeleisen Oct 24 '17 at 06:05
  • Artan, the answer in your linked question is `^((?!//|/\*).)*VPEntity*$`. Have you tried `^((?!//|/\*).)*sys.log`? – Wiktor Stribiżew Oct 24 '17 at 06:27
  • @TimBiegeleisen not always immediately preceded by //, sometimes it has spaces or a tab (\t) – Artan Oct 24 '17 at 06:46
  • @WiktorStribiżew this is not exact duplicate question, since Visual Studio and Visual Studio Code are not the same editor, and they works differently. I have tried it, but it gives an error. – Artan Oct 24 '17 at 06:49
  • [No, `^((?!//|/\*).)*sys\.log` does not produce any error and works as expected.](https://imgur.com/a/vOmZ3) – Wiktor Stribiżew Oct 24 '17 at 06:55
  • @WiktorStribiżew What I am trying to do is to search within files of a folder, so I used the search bar on the left (Ctrl+Shift+F), and apparently it gives different result if you compare it by searching it "in" the file (Ctrl+F) as what you did. you can see the error message in my updated question. – Artan Oct 24 '17 at 07:00
  • *CTRL+SHIFT+F*, pasted the `^((?!//|/\*).)*sys\.log` => [results are still the same, it works.](https://imgur.com/a/4uHfC) Note my VSCode version: 1.2.0 – Wiktor Stribiżew Oct 24 '17 at 07:06
  • Well, then I think it's a VS Code bug. I use version 1.17.1 https://imgur.com/UNA7mo3 – Artan Oct 24 '17 at 07:13
  • Yes, you may log a bug, see [my about dialog](https://imgur.com/a/PL99N) – Wiktor Stribiżew Oct 24 '17 at 07:28
  • Hold off on the bug report. The two ways to search use different regex flavors and that changed earlier this year. See https://stackoverflow.com/questions/42179046/what-flavor-of-regex-does-visual-studio-code-use. I can verify that @WIktor's regex does not work when doing a search across files. – Mark Oct 24 '17 at 14:23
  • For that reason the linked "duplicate" question is NOT a duplicate. – Mark Oct 24 '17 at 14:24
  • And doesn't simply ^\s*sys\.log work for you? – Mark Oct 24 '17 at 14:31
  • @Mark That won't work. There is no 100% safe solution for a non-lookaround pattern here. Perhaps, [`^[^/\n]*(?:/[^*/\n]+)*sys\.log`](https://regex101.com/r/i1Ljuh/2) will work to some extent (test with the Go regex option that does not support lookarounds). – Wiktor Stribiżew Oct 24 '17 at 14:38
  • @Mark Thanks for clarifying that this is not a duplicate question. And your suggestion of the regex works for me. Thank you! – Artan Oct 25 '17 at 03:30
  • Actually @WiktorStribiżew suggestion also works fine for me. Thank you both – Artan Oct 25 '17 at 05:10

1 Answers1

1

For someone who wants to know the answer right away, here it is as suggested by @Mark at the comment section of my question:

  1. First open the "search in files" field using Ctrl+Shift+F
  2. Turn on the Regex function (right-most button of the input field)
  3. Put the following regex:

    ^\s*sys.log

or this regex also works

^[^/\n](?:/[^/\n]+)*sys.log

The above regex-es work for my case.

Before I got this answer, we had a discussion with @Tim and @Wiktor, they both suggested a lookahead regex pattern, and that pattern actually works on older version (V.1.2.0) of Visual Studio Code as @Wiktor pointed out. But apparently, the advanced Regex feature for searching in files is no longer supported since V1.12.0 version. However, it's still working if you search within the file using Ctrl+F.

Thanks to @Tim, @Wiktor and @Mark who have helped to clarify things out.

Artan
  • 91
  • 1
  • 1
  • 9