Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiline find in file (Ctrl+F) does not work for \s or [^] regular expressions #9051

Closed
anseki opened this issue Jul 11, 2016 · 13 comments
Closed
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug editor-find Editor find operations
Milestone

Comments

@anseki
Copy link

anseki commented Jul 11, 2016

  • VSCode Version: 1.3
  • OS Version: Win 8/10

Version 1.3 supported Multiline Find, but Regular Expression seems not work completely.

  • \s doesn't match line breaks.
  • [^] doesn't match line breaks. We have to use [\s\S\n] instead of [^] to make it match any character.
@joaomoreno joaomoreno assigned joaomoreno and alexdima and unassigned joaomoreno Jul 11, 2016
@alexdima
Copy link
Member

@anseki We use JavaScript's regular expression engine behind the scene, so the supported syntax should be that of JavaScript regex. We do not have plans to switch to a different regular expression engine.

@alexdima alexdima added feature-request Request for new features or functionality editor-find Editor find operations labels Jul 11, 2016
@alexdima alexdima added this to the Backlog milestone Jul 11, 2016
@anseki
Copy link
Author

anseki commented Jul 11, 2016

At least, V8 in Electron seems to interpret regular expressions correctly.
For example:
VS Code menu "Help" -> "Toggle Developer Tools" -> "Console"

'<A\nB\nC>'.replace(/<[ABC\s]*>/, 'OK')
'<A\nB\nC>'.replace(/<[^]*>/, 'OK')

Two strings that include line breaks were replaced correctly, and OK was shown.

I think, if regular expression of VS Code differs from JavaScript, the information should be documented. Because the pattern matches a string which doesn't include line break, we might overlook something important.

@alexdima alexdima added bug Issue identified by VS Code Team member as probable bug and removed feature-request Request for new features or functionality labels Jul 11, 2016
@alexdima
Copy link
Member

@anseki Sorry about that! Now I understand what's going on.

To optimize on memory usage we do the following:

  • here we preparse the search string and look for \n or \r. If we find \n or \r in the search string we assume this was a multiline search
  • then, to optimize memory usage (not concatenate the entire buffer into a string) we have two search strategies, either we search line by line (if the search string indicates this is not a multiline search) or we search in the concatenated string.

Looks like the heuristic is wrong, as \s and [^] should also use the multiline version of the find matches.

@anseki
Copy link
Author

anseki commented Jul 11, 2016

Sorry, my wrong English...

I read that code and I thought that this issue is difficult, because it can't decide whether the pattern get multiline or not by only keyword or characters.
For example, [^x], \x0a, [\x09-\x0b] and other patterns also match line break.
I think, only some patterns that are commonly used such as \s and [^] should be supported. And the information should be documented.

[\s\S] and [^] are used to make it match any character.
For example, HTML comment: <!--[^]*?-->

@alexdima alexdima modified the milestones: July 2016, Backlog, August 2016 Jul 11, 2016
@nunoarruda
Copy link

Sorry if the following is not totally related but... I just found that multiline regular expressions work with "Find" but not with "Find/Replace in Files".

With "Find" (works as expected):
screen shot 2016-07-20 at 15 11 05

With "Find/Replace in Files" (does not work as expected):
screen shot 2016-07-20 at 15 11 52

My regular expression is ^<p>Hello(.|\n|\r)+<p>Hello Solar System!<\/p> and my text is:

<p>Hello world!</p>
<p>Hello Solar System!</p><p>Hello Galaxy!</p>

I'm using Visual Studio Code 1.3.1 on OSX El Capitan (10.11.5)

@anseki
Copy link
Author

anseki commented Jul 20, 2016

Hi @nunoarruda,

Strangely enough, it seems to find files in "SEARCH" sidebar when the files are opened by editor. (of course "Find" in editor also find that.)
For example, I tried to find files by <html>[\r\n\s]*<head> at a folder that contains HTML files.
This regular expression should match string in those files. But "No results found" was shown.
I opened one HTML file, and clicked "Refresh" button in "SEARCH" sidebar. Then the file was shown in result list.
And then, I opened one more HTML file, and clicked "Refresh" button. Then two files were shown in result list.

@nunoarruda
Copy link

@anseki I've tried what you've reported with my example and I can reproduce. It matches (but incorrectly) when the file is open but it does not match when the file is closed.

The regex find in VS Code is definitely buggy, needs fixing.

@alexdima
Copy link
Member

alexdima commented Aug 9, 2016

@nunoarruda @anseki The search viewlet goes through different code paths:

  • when a file is opened it searches using the same search implementation as the find widget (thus multi-line works)
  • when a file is not opened it searches in a separate process with a different implementation.

Please create a separate issue for aligning multiline find in the search viewlet.

@alexdima alexdima modified the milestones: Backlog, August 2016 Aug 29, 2016
@JoBrad
Copy link

JoBrad commented Oct 5, 2016

This will be addressed with #13155, right?

@roblourens
Copy link
Member

#13155

@roblourens roblourens added the *duplicate Issue identified as a duplicate of another issue(s) label Oct 28, 2017
@waldyrious
Copy link
Contributor

@roblourens what does "global search" mean in #13155? I thought it was about searching in multiple files, which this issue is not, but please correct me if I'm wrong.

@roblourens roblourens removed the *duplicate Issue identified as a duplicate of another issue(s) label Oct 28, 2017
@roblourens roblourens reopened this Oct 28, 2017
@alexdima alexdima changed the title Multiline Find seems not work completely Multiline find in file (Ctrl+F) does not work for \s or [^] regular expressions Nov 24, 2017
@alexdima
Copy link
Member

alexdima commented Apr 20, 2018

@rebornix This might be a non-issue with our new textbuffer / search implementation?

i.e. there is no longer a need to optimize searching line-by-line

@alexdima alexdima added the editor-textbuffer Editor text buffer label Apr 20, 2018
@alexdima alexdima assigned rebornix and unassigned alexdima Apr 20, 2018
@rebornix rebornix removed the editor-textbuffer Editor text buffer label Sep 12, 2018
@rebornix
Copy link
Member

No longer see above issues as our new text buffer doesn't try to do line by line optimization anymore.

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug editor-find Editor find operations
Projects
None yet
Development

No branches or pull requests

8 participants