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.

15
  • 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? Commented Oct 24, 2017 at 6:05
  • Artan, the answer in your linked question is ^((?!//|/\*).)*VPEntity*$. Have you tried ^((?!//|/\*).)*sys.log? Commented Oct 24, 2017 at 6:27
  • @TimBiegeleisen not always immediately preceded by //, sometimes it has spaces or a tab (\t) Commented Oct 24, 2017 at 6: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. Commented Oct 24, 2017 at 6:49
  • No, ^((?!//|/\*).)*sys\.log does not produce any error and works as expected. Commented Oct 24, 2017 at 6:55

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.