Visual Studio Code: regex expression starts with but not ends with












2














Visual Studio Code uses ripgrep to search in files, which doesn't support look around and backreferences.



I want to build an expression which returns all the phrases which start with a given string and does not end with given string e.g:



Starts with "http://blah.com" but not ends with ".htm"



Matches:



http://blah.com/tmp


Doesn’t match:



http://blah.com/tmp.htm
blah.com/tmp.htm









share|improve this question
























  • I want to search in the whole solution not only in one file
    – GoldenAge
    Nov 19 '18 at 13:12










  • This question has nothing to do with rust itself.
    – hellow
    Nov 19 '18 at 13:22
















2














Visual Studio Code uses ripgrep to search in files, which doesn't support look around and backreferences.



I want to build an expression which returns all the phrases which start with a given string and does not end with given string e.g:



Starts with "http://blah.com" but not ends with ".htm"



Matches:



http://blah.com/tmp


Doesn’t match:



http://blah.com/tmp.htm
blah.com/tmp.htm









share|improve this question
























  • I want to search in the whole solution not only in one file
    – GoldenAge
    Nov 19 '18 at 13:12










  • This question has nothing to do with rust itself.
    – hellow
    Nov 19 '18 at 13:22














2












2








2







Visual Studio Code uses ripgrep to search in files, which doesn't support look around and backreferences.



I want to build an expression which returns all the phrases which start with a given string and does not end with given string e.g:



Starts with "http://blah.com" but not ends with ".htm"



Matches:



http://blah.com/tmp


Doesn’t match:



http://blah.com/tmp.htm
blah.com/tmp.htm









share|improve this question















Visual Studio Code uses ripgrep to search in files, which doesn't support look around and backreferences.



I want to build an expression which returns all the phrases which start with a given string and does not end with given string e.g:



Starts with "http://blah.com" but not ends with ".htm"



Matches:



http://blah.com/tmp


Doesn’t match:



http://blah.com/tmp.htm
blah.com/tmp.htm






regex visual-studio-code






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 13:44









Mark

11k33249




11k33249










asked Nov 19 '18 at 13:06









GoldenAge

499220




499220












  • I want to search in the whole solution not only in one file
    – GoldenAge
    Nov 19 '18 at 13:12










  • This question has nothing to do with rust itself.
    – hellow
    Nov 19 '18 at 13:22


















  • I want to search in the whole solution not only in one file
    – GoldenAge
    Nov 19 '18 at 13:12










  • This question has nothing to do with rust itself.
    – hellow
    Nov 19 '18 at 13:22
















I want to search in the whole solution not only in one file
– GoldenAge
Nov 19 '18 at 13:12




I want to search in the whole solution not only in one file
– GoldenAge
Nov 19 '18 at 13:12












This question has nothing to do with rust itself.
– hellow
Nov 19 '18 at 13:22




This question has nothing to do with rust itself.
– hellow
Nov 19 '18 at 13:22












1 Answer
1






active

oldest

votes


















5














In your settings (to enable lookahead) :



 "search.usePCRE2": true


Your regex (using a negative lookahead):



blah.com(?!.*.htm$)


[Edit] Added the $ if you absolutely want to exclude matches that do not end with the .htm, not just followed somewhere in the string by .htm.



From the v1.29 release notes:




It is also now possible to use backreferences and lookahead assertions
in regex searches, by setting "search.usePCRE2": true. This configures
ripgrep to use the PCRE2 regex engine. While PCRE2 supports many other
features, we only support regex expressions that are still valid in
JavaScript, because open editors are still searched using the editor's
JavaScript-based search.




Positive and negative lookaheads and backreferences.



Also note that a previous solution for this has been deprecated:



// Deprecated. Consider "search.usePCRE2" for advanced regex feature support.
// This setting is deprecated and now falls back on "search.usePCRE2".

"search.useRipgrep": false





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375311%2fvisual-studio-code-regex-expression-starts-with-but-not-ends-with%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    5














    In your settings (to enable lookahead) :



     "search.usePCRE2": true


    Your regex (using a negative lookahead):



    blah.com(?!.*.htm$)


    [Edit] Added the $ if you absolutely want to exclude matches that do not end with the .htm, not just followed somewhere in the string by .htm.



    From the v1.29 release notes:




    It is also now possible to use backreferences and lookahead assertions
    in regex searches, by setting "search.usePCRE2": true. This configures
    ripgrep to use the PCRE2 regex engine. While PCRE2 supports many other
    features, we only support regex expressions that are still valid in
    JavaScript, because open editors are still searched using the editor's
    JavaScript-based search.




    Positive and negative lookaheads and backreferences.



    Also note that a previous solution for this has been deprecated:



    // Deprecated. Consider "search.usePCRE2" for advanced regex feature support.
    // This setting is deprecated and now falls back on "search.usePCRE2".

    "search.useRipgrep": false





    share|improve this answer




























      5














      In your settings (to enable lookahead) :



       "search.usePCRE2": true


      Your regex (using a negative lookahead):



      blah.com(?!.*.htm$)


      [Edit] Added the $ if you absolutely want to exclude matches that do not end with the .htm, not just followed somewhere in the string by .htm.



      From the v1.29 release notes:




      It is also now possible to use backreferences and lookahead assertions
      in regex searches, by setting "search.usePCRE2": true. This configures
      ripgrep to use the PCRE2 regex engine. While PCRE2 supports many other
      features, we only support regex expressions that are still valid in
      JavaScript, because open editors are still searched using the editor's
      JavaScript-based search.




      Positive and negative lookaheads and backreferences.



      Also note that a previous solution for this has been deprecated:



      // Deprecated. Consider "search.usePCRE2" for advanced regex feature support.
      // This setting is deprecated and now falls back on "search.usePCRE2".

      "search.useRipgrep": false





      share|improve this answer


























        5












        5








        5






        In your settings (to enable lookahead) :



         "search.usePCRE2": true


        Your regex (using a negative lookahead):



        blah.com(?!.*.htm$)


        [Edit] Added the $ if you absolutely want to exclude matches that do not end with the .htm, not just followed somewhere in the string by .htm.



        From the v1.29 release notes:




        It is also now possible to use backreferences and lookahead assertions
        in regex searches, by setting "search.usePCRE2": true. This configures
        ripgrep to use the PCRE2 regex engine. While PCRE2 supports many other
        features, we only support regex expressions that are still valid in
        JavaScript, because open editors are still searched using the editor's
        JavaScript-based search.




        Positive and negative lookaheads and backreferences.



        Also note that a previous solution for this has been deprecated:



        // Deprecated. Consider "search.usePCRE2" for advanced regex feature support.
        // This setting is deprecated and now falls back on "search.usePCRE2".

        "search.useRipgrep": false





        share|improve this answer














        In your settings (to enable lookahead) :



         "search.usePCRE2": true


        Your regex (using a negative lookahead):



        blah.com(?!.*.htm$)


        [Edit] Added the $ if you absolutely want to exclude matches that do not end with the .htm, not just followed somewhere in the string by .htm.



        From the v1.29 release notes:




        It is also now possible to use backreferences and lookahead assertions
        in regex searches, by setting "search.usePCRE2": true. This configures
        ripgrep to use the PCRE2 regex engine. While PCRE2 supports many other
        features, we only support regex expressions that are still valid in
        JavaScript, because open editors are still searched using the editor's
        JavaScript-based search.




        Positive and negative lookaheads and backreferences.



        Also note that a previous solution for this has been deprecated:



        // Deprecated. Consider "search.usePCRE2" for advanced regex feature support.
        // This setting is deprecated and now falls back on "search.usePCRE2".

        "search.useRipgrep": false






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 19 '18 at 15:03

























        answered Nov 19 '18 at 13:28









        Mark

        11k33249




        11k33249






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375311%2fvisual-studio-code-regex-expression-starts-with-but-not-ends-with%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            SQL update select statement

            'app-layout' is not a known element: how to share Component with different Modules