Skip to content

Find does not match multi-line regex strings #313

Closed

Description

@Tyriar

The Find dialog (Ctrl+F) does not allow multi-line finds using the \n character as it currently considers each line individually. See TextModel._doFindMatches

Created out of a discussion in #278

Activity

  1. changed the title [-]Find does not match across lines[/-] [+]Find does not match multi-line regex strings[/+] on Nov 23, 2015
  2. alexdima commented on Nov 24, 2015

    @alexdima
    Member

    Indeed, the find is executed on a line by line basis. To implement multi-line search we need to do the following:

    • maintain a fast [offset] <-> [line number, column] mapping data-structure in the model. I think PrefixSumComputer can handle this easily, as long as it's updated correctly on edits.
    • when searching, we need to get the entire text inside the search range as one string
    • run the regex on the one string
    • get back offsets
    • use the above data-structure to convert back to [line number, column] coordinates.

    It is a little bit of work to get all of this done.

  3. added
    feature-request
    on Nov 24, 2015
  4. sushruth commented on Mar 9, 2016

    @sushruth

    👍 (commenting to get updates on this)

  5. ZombieProtectionAgency commented on Mar 11, 2016

    @ZombieProtectionAgency

    Sushruth Sastry (@sushruth) FYI there is a "Subscribe" button to the right on github that lets you follow the thread without commenting.

  6. Ardakilic commented on Apr 15, 2016

    @Ardakilic

    I got the newest update today, and I still suffer from this.

    I almost always use multi line regex, and this is the only feature that's keeping me away from daily usage.

    So +1.

  7. 3-1415926 commented on Apr 22, 2016

    @3-1415926

    +1
    Unfortunately it's a common omission from text editors, presumably due to simplicity of line-based text representation / search model. But nevertheless it's a very useful feature for day-to-day work.
    Please please fix!

  8. jmrnilsson commented on May 2, 2016

    @jmrnilsson

    👍 I would love this feature as well.

  9. LyZane commented on May 5, 2016

    @LyZane

    +10086

  10. klauszhang commented on May 6, 2016

    @klauszhang

    This can be very useful. +++. hope we can have this soon!

  11. 0x3333 commented on May 6, 2016

    @0x3333

    Come on people. Subscribe. Stop spamming. Will not help comment on this.

  12. 21 remaining items

  13. g5codyswartz commented on Oct 7, 2016

    @g5codyswartz

    I'm unable to get this to match
    image

    Running this on regex101 seems to work fine
    image

    Another question is if VS Code's regex search supports inline flags like Sublime ie (single line, . matches new line): (?s)<fieldset>.*<legend>
    In this example this is useful for finding a legend tag after or possibly within a fieldset tag, whether or not it's on the next line from fieldset.

  14. Tyriar commented on Oct 7, 2016

    @Tyriar
    ContributorAuthor

    Cody Swartz (@g5codyswartz) nice find, I created #13369

    Not sure about inline flags.

  15. johankvint commented on Feb 24, 2017

    @johankvint

    Is this fixed? Still can't do multiline regex on VS Code 1.9.1, Mac

  16. joeshub commented on Apr 1, 2017

    @joeshub

    what was the resolution to this issue?

  17. tracker1 commented on Apr 13, 2017

    @tracker1

    Joe Seifi (@joeshub), you should be able to match against newlines now with \s ... I'm also able to match more explicitly with \r?\n (CR is for potentially crlf/windows line endings). It's working for me in the most recent march 2017 release (1.11.2).

  18. joeshub commented on Apr 14, 2017

    @joeshub

    Michael J. Ryan (@tracker1) I see thank you. this works but only for open files in VS Code. Please tell me I don't have to open every file in my project before searching w/ regex :)

  19. tdhsmith commented on Apr 27, 2017

    @tdhsmith

    Yeah that behavior (where "find in files" only returns results in open buffers) is misleading at best. Nothing even warns you that it's occurring.

  20. umpirsky commented on Jul 8, 2017

    @umpirsky

    Why is this closed? Multiline regex find and replace does not work in 1.13.1. Looks like it finds only in opened buffers, but how useful is that?

  21. windhandel commented on Jul 28, 2017

    @windhandel

    In case anyone is still struggling with this.

    The workaround for doing something like a negative lookbehind assertion using mult-lines. You can do something like.

    (?<!configService'[\s\S\r]+?)config.

    This is searching for the string "config." (no double quotes) that is not proceeded by "configService'" (no double quotes) and any/all characters with multiple lines in between.

  22. windhandel commented on Jul 28, 2017

    @windhandel

    As an aside, I stopped logging bugs against Microsoft products because they'll never fix them for you even if they appear high severity years ago.

    I haven't bothered for over 5 years. It's a waste of time, even if the issue high severity. You can google my name and Microsoft bug and see my rants at times in the past. Now I'm zen about it and just don't care. ;)

    There's a reason why I'm no longer an FTE.

    Here's a nice WCF bug that's active from 2013 - http://www.beta.microsoft.com/VisualStudio/feedbackdetail/view/779111/wcf-rest-service-two-set-cookie-http-headers-invalid-set-cookie-header-syntax

  23. g5codyswartz commented on Jul 28, 2017

    @g5codyswartz

    Jeff Fischer (@windhandel)
    It's nice with VSCode as I believe this is a separate section of the team that gets to operate differently. Especially since this is open source you get to see a lot more of the ins & outs of how this team is operating. Given it's open source you get the opportunity to fix the code up yourself if you have the time and know how.

  24. CodeCharm commented on Aug 19, 2017

    @CodeCharm

    Jeff Fischer (@windhandel) It's a double edged sword. You might write bug-free code (do you?) but if nobody else is using it, it's not so great. On the other hand, if you are a mere mortal like the rest of us, and you write code that a lot of people use, you will be prompted to publish it with what you hope are not too many bugs as well as requests for new features. Life becomes a careful balance of fixing just enough bugs, adding just enough new features, to keep your code popular and useful. And, especially in the world of open source where anyone can fix bugs, we hope that everyone helps keep the balance.

    BTW, did you know that WCF is open source? https://github.com/dotnet/wcf

  25. kuaipaowoniu commented on Aug 22, 2017

    @kuaipaowoniu

    Format my code, appear in the following format:
    _self
    .model
    .personClassify(classify);
    But I want to keep my code in the same line, for example:

    _self.model.personClassify(classify);

    How should I configure?

  26. CodeCharm commented on Oct 12, 2017

    @CodeCharm

    键盘人生 (@kuaipaowoniu) This is not that hard, but you'll want to learn more about regular expressions.

    In VS Code, 1.17.0, search for this Regular Expression
    ([^\n]*)\n\.
    and use this for the Replace part
    $1.

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

Metadata

Metadata

Labels

editor-findfeature-request

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions