Scala regex and parentheses









up vote
0
down vote

favorite












I have the following string:



tagged.big) AND tagged.medium


I need to extract everything from this string that starts from tagged. and ends with one or more whitespaces or )



This is my current regex pattern:



tagged.[),S]+


From the example string I expect:



tagged.big
tagged.medium


but right now it returns:



tagged.big)
tagged.medium


What am I doing wrong and how to fix it?










share|improve this question





















  • regex101.com/r/LrSZe7/2 Check it out this pattern, if it works, i can explain.
    – lucas_7_94
    Nov 10 at 17:43











  • Thanks, this is exactly what I need!
    – alexanoid
    Nov 10 at 17:47










  • I found that tagged.big1 returns tagged.big but should also return tagged.big1.. and the same for tagged.big2 Could you please check it?
    – alexanoid
    Nov 10 at 17:50











  • regex101.com/r/LrSZe7/4 Added .big1 (you can see it at the end of the list) and returns it without problem, re-check in your source program if it works.
    – lucas_7_94
    Nov 10 at 17:56











  • thanks, works good right now
    – alexanoid
    Nov 10 at 17:59














up vote
0
down vote

favorite












I have the following string:



tagged.big) AND tagged.medium


I need to extract everything from this string that starts from tagged. and ends with one or more whitespaces or )



This is my current regex pattern:



tagged.[),S]+


From the example string I expect:



tagged.big
tagged.medium


but right now it returns:



tagged.big)
tagged.medium


What am I doing wrong and how to fix it?










share|improve this question





















  • regex101.com/r/LrSZe7/2 Check it out this pattern, if it works, i can explain.
    – lucas_7_94
    Nov 10 at 17:43











  • Thanks, this is exactly what I need!
    – alexanoid
    Nov 10 at 17:47










  • I found that tagged.big1 returns tagged.big but should also return tagged.big1.. and the same for tagged.big2 Could you please check it?
    – alexanoid
    Nov 10 at 17:50











  • regex101.com/r/LrSZe7/4 Added .big1 (you can see it at the end of the list) and returns it without problem, re-check in your source program if it works.
    – lucas_7_94
    Nov 10 at 17:56











  • thanks, works good right now
    – alexanoid
    Nov 10 at 17:59












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have the following string:



tagged.big) AND tagged.medium


I need to extract everything from this string that starts from tagged. and ends with one or more whitespaces or )



This is my current regex pattern:



tagged.[),S]+


From the example string I expect:



tagged.big
tagged.medium


but right now it returns:



tagged.big)
tagged.medium


What am I doing wrong and how to fix it?










share|improve this question













I have the following string:



tagged.big) AND tagged.medium


I need to extract everything from this string that starts from tagged. and ends with one or more whitespaces or )



This is my current regex pattern:



tagged.[),S]+


From the example string I expect:



tagged.big
tagged.medium


but right now it returns:



tagged.big)
tagged.medium


What am I doing wrong and how to fix it?







regex scala






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 17:35









alexanoid

7,0521177173




7,0521177173











  • regex101.com/r/LrSZe7/2 Check it out this pattern, if it works, i can explain.
    – lucas_7_94
    Nov 10 at 17:43











  • Thanks, this is exactly what I need!
    – alexanoid
    Nov 10 at 17:47










  • I found that tagged.big1 returns tagged.big but should also return tagged.big1.. and the same for tagged.big2 Could you please check it?
    – alexanoid
    Nov 10 at 17:50











  • regex101.com/r/LrSZe7/4 Added .big1 (you can see it at the end of the list) and returns it without problem, re-check in your source program if it works.
    – lucas_7_94
    Nov 10 at 17:56











  • thanks, works good right now
    – alexanoid
    Nov 10 at 17:59
















  • regex101.com/r/LrSZe7/2 Check it out this pattern, if it works, i can explain.
    – lucas_7_94
    Nov 10 at 17:43











  • Thanks, this is exactly what I need!
    – alexanoid
    Nov 10 at 17:47










  • I found that tagged.big1 returns tagged.big but should also return tagged.big1.. and the same for tagged.big2 Could you please check it?
    – alexanoid
    Nov 10 at 17:50











  • regex101.com/r/LrSZe7/4 Added .big1 (you can see it at the end of the list) and returns it without problem, re-check in your source program if it works.
    – lucas_7_94
    Nov 10 at 17:56











  • thanks, works good right now
    – alexanoid
    Nov 10 at 17:59















regex101.com/r/LrSZe7/2 Check it out this pattern, if it works, i can explain.
– lucas_7_94
Nov 10 at 17:43





regex101.com/r/LrSZe7/2 Check it out this pattern, if it works, i can explain.
– lucas_7_94
Nov 10 at 17:43













Thanks, this is exactly what I need!
– alexanoid
Nov 10 at 17:47




Thanks, this is exactly what I need!
– alexanoid
Nov 10 at 17:47












I found that tagged.big1 returns tagged.big but should also return tagged.big1.. and the same for tagged.big2 Could you please check it?
– alexanoid
Nov 10 at 17:50





I found that tagged.big1 returns tagged.big but should also return tagged.big1.. and the same for tagged.big2 Could you please check it?
– alexanoid
Nov 10 at 17:50













regex101.com/r/LrSZe7/4 Added .big1 (you can see it at the end of the list) and returns it without problem, re-check in your source program if it works.
– lucas_7_94
Nov 10 at 17:56





regex101.com/r/LrSZe7/4 Added .big1 (you can see it at the end of the list) and returns it without problem, re-check in your source program if it works.
– lucas_7_94
Nov 10 at 17:56













thanks, works good right now
– alexanoid
Nov 10 at 17:59




thanks, works good right now
– alexanoid
Nov 10 at 17:59












2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










In your regex you use tagged.[),S]+ which contains a character class with ), comma and S which matches not a whitespace character. The S also matches a comma and ) so that could be shortened to just S+. But that would match too much.



To match your values, you could for exampe use a word character w or add to the character class what you would allow to match:



tagged.w+



Regex demo



That will match




  • tagged. Match tagged.


  • w+ Match 1+ word characters

Regex demo






share|improve this answer



























    up vote
    1
    down vote













    Final pattern : tagged.[^Ws]+ (You can see a further explanation on the site)



    So it follows:



    • 'tagged.' : matches any string with start with tagged.

    • [^ ]: this matches a single character which is NOT presented on the set.

    • [^Ws] : matches a single character which is not a non-word or whitespace


    • + : quantifier greedy, matches one or unlimited times the set.





    share|improve this answer






















    • [$] matches a $ char, not an end of the string. . that is not escaped matches any char, not just a dot.
      – Wiktor Stribiżew
      Nov 10 at 20:15










    • Great to know, thanks!
      – lucas_7_94
      Nov 10 at 20:17










    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',
    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%2f53241648%2fscala-regex-and-parentheses%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








    up vote
    2
    down vote



    accepted










    In your regex you use tagged.[),S]+ which contains a character class with ), comma and S which matches not a whitespace character. The S also matches a comma and ) so that could be shortened to just S+. But that would match too much.



    To match your values, you could for exampe use a word character w or add to the character class what you would allow to match:



    tagged.w+



    Regex demo



    That will match




    • tagged. Match tagged.


    • w+ Match 1+ word characters

    Regex demo






    share|improve this answer
























      up vote
      2
      down vote



      accepted










      In your regex you use tagged.[),S]+ which contains a character class with ), comma and S which matches not a whitespace character. The S also matches a comma and ) so that could be shortened to just S+. But that would match too much.



      To match your values, you could for exampe use a word character w or add to the character class what you would allow to match:



      tagged.w+



      Regex demo



      That will match




      • tagged. Match tagged.


      • w+ Match 1+ word characters

      Regex demo






      share|improve this answer






















        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        In your regex you use tagged.[),S]+ which contains a character class with ), comma and S which matches not a whitespace character. The S also matches a comma and ) so that could be shortened to just S+. But that would match too much.



        To match your values, you could for exampe use a word character w or add to the character class what you would allow to match:



        tagged.w+



        Regex demo



        That will match




        • tagged. Match tagged.


        • w+ Match 1+ word characters

        Regex demo






        share|improve this answer












        In your regex you use tagged.[),S]+ which contains a character class with ), comma and S which matches not a whitespace character. The S also matches a comma and ) so that could be shortened to just S+. But that would match too much.



        To match your values, you could for exampe use a word character w or add to the character class what you would allow to match:



        tagged.w+



        Regex demo



        That will match




        • tagged. Match tagged.


        • w+ Match 1+ word characters

        Regex demo







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 18:25









        The fourth bird

        19.5k71323




        19.5k71323






















            up vote
            1
            down vote













            Final pattern : tagged.[^Ws]+ (You can see a further explanation on the site)



            So it follows:



            • 'tagged.' : matches any string with start with tagged.

            • [^ ]: this matches a single character which is NOT presented on the set.

            • [^Ws] : matches a single character which is not a non-word or whitespace


            • + : quantifier greedy, matches one or unlimited times the set.





            share|improve this answer






















            • [$] matches a $ char, not an end of the string. . that is not escaped matches any char, not just a dot.
              – Wiktor Stribiżew
              Nov 10 at 20:15










            • Great to know, thanks!
              – lucas_7_94
              Nov 10 at 20:17














            up vote
            1
            down vote













            Final pattern : tagged.[^Ws]+ (You can see a further explanation on the site)



            So it follows:



            • 'tagged.' : matches any string with start with tagged.

            • [^ ]: this matches a single character which is NOT presented on the set.

            • [^Ws] : matches a single character which is not a non-word or whitespace


            • + : quantifier greedy, matches one or unlimited times the set.





            share|improve this answer






















            • [$] matches a $ char, not an end of the string. . that is not escaped matches any char, not just a dot.
              – Wiktor Stribiżew
              Nov 10 at 20:15










            • Great to know, thanks!
              – lucas_7_94
              Nov 10 at 20:17












            up vote
            1
            down vote










            up vote
            1
            down vote









            Final pattern : tagged.[^Ws]+ (You can see a further explanation on the site)



            So it follows:



            • 'tagged.' : matches any string with start with tagged.

            • [^ ]: this matches a single character which is NOT presented on the set.

            • [^Ws] : matches a single character which is not a non-word or whitespace


            • + : quantifier greedy, matches one or unlimited times the set.





            share|improve this answer














            Final pattern : tagged.[^Ws]+ (You can see a further explanation on the site)



            So it follows:



            • 'tagged.' : matches any string with start with tagged.

            • [^ ]: this matches a single character which is NOT presented on the set.

            • [^Ws] : matches a single character which is not a non-word or whitespace


            • + : quantifier greedy, matches one or unlimited times the set.






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 10 at 20:17

























            answered Nov 10 at 18:03









            lucas_7_94

            1336




            1336











            • [$] matches a $ char, not an end of the string. . that is not escaped matches any char, not just a dot.
              – Wiktor Stribiżew
              Nov 10 at 20:15










            • Great to know, thanks!
              – lucas_7_94
              Nov 10 at 20:17
















            • [$] matches a $ char, not an end of the string. . that is not escaped matches any char, not just a dot.
              – Wiktor Stribiżew
              Nov 10 at 20:15










            • Great to know, thanks!
              – lucas_7_94
              Nov 10 at 20:17















            [$] matches a $ char, not an end of the string. . that is not escaped matches any char, not just a dot.
            – Wiktor Stribiżew
            Nov 10 at 20:15




            [$] matches a $ char, not an end of the string. . that is not escaped matches any char, not just a dot.
            – Wiktor Stribiżew
            Nov 10 at 20:15












            Great to know, thanks!
            – lucas_7_94
            Nov 10 at 20:17




            Great to know, thanks!
            – lucas_7_94
            Nov 10 at 20:17

















            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%2f53241648%2fscala-regex-and-parentheses%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

            Use pre created SQLite database for Android project in kotlin

            Darth Vader #20

            Ondo