Skip to content

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

Closed

Description

@anseki
  • 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.

Activity

  1. alexdima commented on Jul 11, 2016

    @alexdima
    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.

  2. added
    feature-request
    editor-find
    on Jul 11, 2016
  3. anseki commented on Jul 11, 2016

    @anseki
    Author

    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.

  4. added
    bug
    and removed
    feature-request
    on Jul 11, 2016
  5. alexdima commented on Jul 11, 2016

    @alexdima
    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.

  6. anseki commented on Jul 11, 2016

    @anseki
    Author

    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: <!--[^]*?-->

  7. 8 remaining items

  8. roblourens commented on Oct 28, 2017

    @roblourens
    Member
  9. added
    *duplicate
    on Oct 28, 2017
  10. waldyrious commented on Oct 28, 2017

    @waldyrious
    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.

  11. removed
    *duplicate
    on Oct 28, 2017
  12. changed the title [-]Multiline Find seems not work completely[/-] [+]Multiline find in file (Ctrl+F) does not work for \s or [^] regular expressions[/+] on Nov 24, 2017
  13. alexdima commented on Apr 20, 2018

    @alexdima
    Member

    Peng Lyu (@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

  14. rebornix commented on Sep 21, 2018

    @rebornix
    Contributor

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

  15. locked and limited conversation to collaborators on Nov 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugeditor-find

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions