Flutter cannot parse regex












4















Flutter cannot parse this working regex, and doesn't return any error or info.



(?<=id=)[^&]+


However, when I add it into my Flutter app:



print("before");
new RegExp(r'(?<=id=)[^&]+');
print("after");


It doesn't do anything, doesn't return any error. The print("after"); never gets executed. It doesn't completly freeze the app, because it's in async.










share|improve this question





























    4















    Flutter cannot parse this working regex, and doesn't return any error or info.



    (?<=id=)[^&]+


    However, when I add it into my Flutter app:



    print("before");
    new RegExp(r'(?<=id=)[^&]+');
    print("after");


    It doesn't do anything, doesn't return any error. The print("after"); never gets executed. It doesn't completly freeze the app, because it's in async.










    share|improve this question



























      4












      4








      4








      Flutter cannot parse this working regex, and doesn't return any error or info.



      (?<=id=)[^&]+


      However, when I add it into my Flutter app:



      print("before");
      new RegExp(r'(?<=id=)[^&]+');
      print("after");


      It doesn't do anything, doesn't return any error. The print("after"); never gets executed. It doesn't completly freeze the app, because it's in async.










      share|improve this question
















      Flutter cannot parse this working regex, and doesn't return any error or info.



      (?<=id=)[^&]+


      However, when I add it into my Flutter app:



      print("before");
      new RegExp(r'(?<=id=)[^&]+');
      print("after");


      It doesn't do anything, doesn't return any error. The print("after"); never gets executed. It doesn't completly freeze the app, because it's in async.







      regex dart flutter






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 2 at 7:49









      Wiktor Stribiżew

      324k16146226




      324k16146226










      asked Dec 31 '18 at 10:34









      Makalone LOgmanMakalone LOgman

      1078




      1078
























          2 Answers
          2






          active

          oldest

          votes


















          2














          Dart compiled for the Web supports lokbehinds, but the current version of native Dart (including Flutter) does not support lookbehinds (source).



          In your case, you want to match a string after a specific string. All you need is to declare a capturing group in your pattern and then access that submatch:



          RegExp regExp = new RegExp(r"id=([^&]+)");
          String s = "http://example.com?id=some.thing.com&other=parameter; http://example.com?id=some.thing.com";
          Iterable<Match> matches = regExp.allMatches(s);
          for (Match match in matches) {
          print(match.group(1));
          }


          Output:



          some.thing.com
          some.thing.com


          Here, id=([^&]+) matches id= and then the ([^&]+) capturing group #1 matches and captures into Group 1 any one or more chars other than &. Note you may make it safer if you add [?&] before id to only match id and not thisid query param: [?&]id=([^&]+).






          share|improve this answer































            1














            I assume this is https://github.com/dart-lang/sdk/issues/34935




            Bring Dart's RegExp support in line with JavaScript: lookbehinds, property escapes, and named groups.







            share|improve this answer
























            • So... Its not supported in current version of Flutter? So I will have to use just id=[^&]+ and then ReplaceAll id= with '' .

              – Makalone LOgman
              Dec 31 '18 at 10:40






            • 1





              Yes, Flutter depends on Dart for RegExp and Dart limits itself to what is supported in the browser, but they are a bit behind, because I think your example is now supported in recent browser versions, but not yet in Dart. I don't have deep RegExp knowledge and I'm not sure what a good workaround would be.

              – Günter Zöchbauer
              Dec 31 '18 at 10:47











            • Ok, thanks then.

              – Makalone LOgman
              Dec 31 '18 at 11:15











            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%2f53986424%2fflutter-cannot-parse-regex%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            Dart compiled for the Web supports lokbehinds, but the current version of native Dart (including Flutter) does not support lookbehinds (source).



            In your case, you want to match a string after a specific string. All you need is to declare a capturing group in your pattern and then access that submatch:



            RegExp regExp = new RegExp(r"id=([^&]+)");
            String s = "http://example.com?id=some.thing.com&other=parameter; http://example.com?id=some.thing.com";
            Iterable<Match> matches = regExp.allMatches(s);
            for (Match match in matches) {
            print(match.group(1));
            }


            Output:



            some.thing.com
            some.thing.com


            Here, id=([^&]+) matches id= and then the ([^&]+) capturing group #1 matches and captures into Group 1 any one or more chars other than &. Note you may make it safer if you add [?&] before id to only match id and not thisid query param: [?&]id=([^&]+).






            share|improve this answer




























              2














              Dart compiled for the Web supports lokbehinds, but the current version of native Dart (including Flutter) does not support lookbehinds (source).



              In your case, you want to match a string after a specific string. All you need is to declare a capturing group in your pattern and then access that submatch:



              RegExp regExp = new RegExp(r"id=([^&]+)");
              String s = "http://example.com?id=some.thing.com&other=parameter; http://example.com?id=some.thing.com";
              Iterable<Match> matches = regExp.allMatches(s);
              for (Match match in matches) {
              print(match.group(1));
              }


              Output:



              some.thing.com
              some.thing.com


              Here, id=([^&]+) matches id= and then the ([^&]+) capturing group #1 matches and captures into Group 1 any one or more chars other than &. Note you may make it safer if you add [?&] before id to only match id and not thisid query param: [?&]id=([^&]+).






              share|improve this answer


























                2












                2








                2







                Dart compiled for the Web supports lokbehinds, but the current version of native Dart (including Flutter) does not support lookbehinds (source).



                In your case, you want to match a string after a specific string. All you need is to declare a capturing group in your pattern and then access that submatch:



                RegExp regExp = new RegExp(r"id=([^&]+)");
                String s = "http://example.com?id=some.thing.com&other=parameter; http://example.com?id=some.thing.com";
                Iterable<Match> matches = regExp.allMatches(s);
                for (Match match in matches) {
                print(match.group(1));
                }


                Output:



                some.thing.com
                some.thing.com


                Here, id=([^&]+) matches id= and then the ([^&]+) capturing group #1 matches and captures into Group 1 any one or more chars other than &. Note you may make it safer if you add [?&] before id to only match id and not thisid query param: [?&]id=([^&]+).






                share|improve this answer













                Dart compiled for the Web supports lokbehinds, but the current version of native Dart (including Flutter) does not support lookbehinds (source).



                In your case, you want to match a string after a specific string. All you need is to declare a capturing group in your pattern and then access that submatch:



                RegExp regExp = new RegExp(r"id=([^&]+)");
                String s = "http://example.com?id=some.thing.com&other=parameter; http://example.com?id=some.thing.com";
                Iterable<Match> matches = regExp.allMatches(s);
                for (Match match in matches) {
                print(match.group(1));
                }


                Output:



                some.thing.com
                some.thing.com


                Here, id=([^&]+) matches id= and then the ([^&]+) capturing group #1 matches and captures into Group 1 any one or more chars other than &. Note you may make it safer if you add [?&] before id to only match id and not thisid query param: [?&]id=([^&]+).







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 31 '18 at 12:15









                Wiktor StribiżewWiktor Stribiżew

                324k16146226




                324k16146226

























                    1














                    I assume this is https://github.com/dart-lang/sdk/issues/34935




                    Bring Dart's RegExp support in line with JavaScript: lookbehinds, property escapes, and named groups.







                    share|improve this answer
























                    • So... Its not supported in current version of Flutter? So I will have to use just id=[^&]+ and then ReplaceAll id= with '' .

                      – Makalone LOgman
                      Dec 31 '18 at 10:40






                    • 1





                      Yes, Flutter depends on Dart for RegExp and Dart limits itself to what is supported in the browser, but they are a bit behind, because I think your example is now supported in recent browser versions, but not yet in Dart. I don't have deep RegExp knowledge and I'm not sure what a good workaround would be.

                      – Günter Zöchbauer
                      Dec 31 '18 at 10:47











                    • Ok, thanks then.

                      – Makalone LOgman
                      Dec 31 '18 at 11:15
















                    1














                    I assume this is https://github.com/dart-lang/sdk/issues/34935




                    Bring Dart's RegExp support in line with JavaScript: lookbehinds, property escapes, and named groups.







                    share|improve this answer
























                    • So... Its not supported in current version of Flutter? So I will have to use just id=[^&]+ and then ReplaceAll id= with '' .

                      – Makalone LOgman
                      Dec 31 '18 at 10:40






                    • 1





                      Yes, Flutter depends on Dart for RegExp and Dart limits itself to what is supported in the browser, but they are a bit behind, because I think your example is now supported in recent browser versions, but not yet in Dart. I don't have deep RegExp knowledge and I'm not sure what a good workaround would be.

                      – Günter Zöchbauer
                      Dec 31 '18 at 10:47











                    • Ok, thanks then.

                      – Makalone LOgman
                      Dec 31 '18 at 11:15














                    1












                    1








                    1







                    I assume this is https://github.com/dart-lang/sdk/issues/34935




                    Bring Dart's RegExp support in line with JavaScript: lookbehinds, property escapes, and named groups.







                    share|improve this answer













                    I assume this is https://github.com/dart-lang/sdk/issues/34935




                    Bring Dart's RegExp support in line with JavaScript: lookbehinds, property escapes, and named groups.








                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Dec 31 '18 at 10:37









                    Günter ZöchbauerGünter Zöchbauer

                    332k701006941




                    332k701006941













                    • So... Its not supported in current version of Flutter? So I will have to use just id=[^&]+ and then ReplaceAll id= with '' .

                      – Makalone LOgman
                      Dec 31 '18 at 10:40






                    • 1





                      Yes, Flutter depends on Dart for RegExp and Dart limits itself to what is supported in the browser, but they are a bit behind, because I think your example is now supported in recent browser versions, but not yet in Dart. I don't have deep RegExp knowledge and I'm not sure what a good workaround would be.

                      – Günter Zöchbauer
                      Dec 31 '18 at 10:47











                    • Ok, thanks then.

                      – Makalone LOgman
                      Dec 31 '18 at 11:15



















                    • So... Its not supported in current version of Flutter? So I will have to use just id=[^&]+ and then ReplaceAll id= with '' .

                      – Makalone LOgman
                      Dec 31 '18 at 10:40






                    • 1





                      Yes, Flutter depends on Dart for RegExp and Dart limits itself to what is supported in the browser, but they are a bit behind, because I think your example is now supported in recent browser versions, but not yet in Dart. I don't have deep RegExp knowledge and I'm not sure what a good workaround would be.

                      – Günter Zöchbauer
                      Dec 31 '18 at 10:47











                    • Ok, thanks then.

                      – Makalone LOgman
                      Dec 31 '18 at 11:15

















                    So... Its not supported in current version of Flutter? So I will have to use just id=[^&]+ and then ReplaceAll id= with '' .

                    – Makalone LOgman
                    Dec 31 '18 at 10:40





                    So... Its not supported in current version of Flutter? So I will have to use just id=[^&]+ and then ReplaceAll id= with '' .

                    – Makalone LOgman
                    Dec 31 '18 at 10:40




                    1




                    1





                    Yes, Flutter depends on Dart for RegExp and Dart limits itself to what is supported in the browser, but they are a bit behind, because I think your example is now supported in recent browser versions, but not yet in Dart. I don't have deep RegExp knowledge and I'm not sure what a good workaround would be.

                    – Günter Zöchbauer
                    Dec 31 '18 at 10:47





                    Yes, Flutter depends on Dart for RegExp and Dart limits itself to what is supported in the browser, but they are a bit behind, because I think your example is now supported in recent browser versions, but not yet in Dart. I don't have deep RegExp knowledge and I'm not sure what a good workaround would be.

                    – Günter Zöchbauer
                    Dec 31 '18 at 10:47













                    Ok, thanks then.

                    – Makalone LOgman
                    Dec 31 '18 at 11:15





                    Ok, thanks then.

                    – Makalone LOgman
                    Dec 31 '18 at 11:15


















                    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.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53986424%2fflutter-cannot-parse-regex%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

                    MongoDB - Not Authorized To Execute Command

                    How to fix TextFormField cause rebuild widget in Flutter

                    in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith