how to capture group within capture group?












0















for example, string:



bla bla bla (bla oops bla
bla bla bla
bla bla bla) bla oops
bla bla bla
oops bla (bla bla oops
bla)


how i can get 'oops' between brackets?
first, i get text between brackets:



(?<=()([wW]*?)(?=))


can i in the same regex capture group within capture group (find 'oops' within capture group)?










share|improve this question

























  • If you have PHP, ([^()]*Koops(?=[^()]*)). In .NET, (?<=([^()]*)oops(?=[^()]*)).

    – Wiktor Stribiżew
    Nov 27 '18 at 17:31













  • See stackoverflow.com/questions/23342679/…, too

    – Wiktor Stribiżew
    Nov 27 '18 at 17:34













  • Eventually, a lot depends on what you need to get in the end (usually, extract or replace).

    – Wiktor Stribiżew
    Nov 27 '18 at 17:46











  • What is the language?

    – JohnyL
    Nov 27 '18 at 19:58











  • @WiktorStribiżew thank you so much for php-regex!!!!!!!!! Now I understand how K works.

    – Alexander
    Nov 28 '18 at 4:28


















0















for example, string:



bla bla bla (bla oops bla
bla bla bla
bla bla bla) bla oops
bla bla bla
oops bla (bla bla oops
bla)


how i can get 'oops' between brackets?
first, i get text between brackets:



(?<=()([wW]*?)(?=))


can i in the same regex capture group within capture group (find 'oops' within capture group)?










share|improve this question

























  • If you have PHP, ([^()]*Koops(?=[^()]*)). In .NET, (?<=([^()]*)oops(?=[^()]*)).

    – Wiktor Stribiżew
    Nov 27 '18 at 17:31













  • See stackoverflow.com/questions/23342679/…, too

    – Wiktor Stribiżew
    Nov 27 '18 at 17:34













  • Eventually, a lot depends on what you need to get in the end (usually, extract or replace).

    – Wiktor Stribiżew
    Nov 27 '18 at 17:46











  • What is the language?

    – JohnyL
    Nov 27 '18 at 19:58











  • @WiktorStribiżew thank you so much for php-regex!!!!!!!!! Now I understand how K works.

    – Alexander
    Nov 28 '18 at 4:28
















0












0








0








for example, string:



bla bla bla (bla oops bla
bla bla bla
bla bla bla) bla oops
bla bla bla
oops bla (bla bla oops
bla)


how i can get 'oops' between brackets?
first, i get text between brackets:



(?<=()([wW]*?)(?=))


can i in the same regex capture group within capture group (find 'oops' within capture group)?










share|improve this question
















for example, string:



bla bla bla (bla oops bla
bla bla bla
bla bla bla) bla oops
bla bla bla
oops bla (bla bla oops
bla)


how i can get 'oops' between brackets?
first, i get text between brackets:



(?<=()([wW]*?)(?=))


can i in the same regex capture group within capture group (find 'oops' within capture group)?







regex pcre






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 28 '18 at 8:17









Wiktor Stribiżew

321k16141223




321k16141223










asked Nov 27 '18 at 17:30









AlexanderAlexander

255




255













  • If you have PHP, ([^()]*Koops(?=[^()]*)). In .NET, (?<=([^()]*)oops(?=[^()]*)).

    – Wiktor Stribiżew
    Nov 27 '18 at 17:31













  • See stackoverflow.com/questions/23342679/…, too

    – Wiktor Stribiżew
    Nov 27 '18 at 17:34













  • Eventually, a lot depends on what you need to get in the end (usually, extract or replace).

    – Wiktor Stribiżew
    Nov 27 '18 at 17:46











  • What is the language?

    – JohnyL
    Nov 27 '18 at 19:58











  • @WiktorStribiżew thank you so much for php-regex!!!!!!!!! Now I understand how K works.

    – Alexander
    Nov 28 '18 at 4:28





















  • If you have PHP, ([^()]*Koops(?=[^()]*)). In .NET, (?<=([^()]*)oops(?=[^()]*)).

    – Wiktor Stribiżew
    Nov 27 '18 at 17:31













  • See stackoverflow.com/questions/23342679/…, too

    – Wiktor Stribiżew
    Nov 27 '18 at 17:34













  • Eventually, a lot depends on what you need to get in the end (usually, extract or replace).

    – Wiktor Stribiżew
    Nov 27 '18 at 17:46











  • What is the language?

    – JohnyL
    Nov 27 '18 at 19:58











  • @WiktorStribiżew thank you so much for php-regex!!!!!!!!! Now I understand how K works.

    – Alexander
    Nov 28 '18 at 4:28



















If you have PHP, ([^()]*Koops(?=[^()]*)). In .NET, (?<=([^()]*)oops(?=[^()]*)).

– Wiktor Stribiżew
Nov 27 '18 at 17:31







If you have PHP, ([^()]*Koops(?=[^()]*)). In .NET, (?<=([^()]*)oops(?=[^()]*)).

– Wiktor Stribiżew
Nov 27 '18 at 17:31















See stackoverflow.com/questions/23342679/…, too

– Wiktor Stribiżew
Nov 27 '18 at 17:34







See stackoverflow.com/questions/23342679/…, too

– Wiktor Stribiżew
Nov 27 '18 at 17:34















Eventually, a lot depends on what you need to get in the end (usually, extract or replace).

– Wiktor Stribiżew
Nov 27 '18 at 17:46





Eventually, a lot depends on what you need to get in the end (usually, extract or replace).

– Wiktor Stribiżew
Nov 27 '18 at 17:46













What is the language?

– JohnyL
Nov 27 '18 at 19:58





What is the language?

– JohnyL
Nov 27 '18 at 19:58













@WiktorStribiżew thank you so much for php-regex!!!!!!!!! Now I understand how K works.

– Alexander
Nov 28 '18 at 4:28







@WiktorStribiżew thank you so much for php-regex!!!!!!!!! Now I understand how K works.

– Alexander
Nov 28 '18 at 4:28














2 Answers
2






active

oldest

votes


















1














You may use



(?:G(?!A)|()[^()]*?Koops


Or, if you must check for the closing parentheses, add a lookahead at the end:



(?:G(?!A)|()[^()]*?Koops(?=[^()]*))


See the regex demo.



Details





  • (?:G(?!A)|() - ( or end of the previous match (G(?!A))


  • [^()]*? - any 0+ chars other than ( and )


  • K - match reset operator


  • oops - the word you need (wrap with b if you need a whole word match)


  • (?=[^()]*)) - a positive lookahead that requires 0+ chars other than ( and ) up to the first ) to appear immediately to the right of the current location.






share|improve this answer
























  • thank you very much. You made me study regular espressions in more detail. thanks again.

    – Alexander
    Nov 28 '18 at 8:39



















0














You can use the following regex:



(?<=()([wW]*?(oops)[wW]*?)(?=))


Basically it injects a Group looking for 'oops' then it doubles the '[wW]*?' matching both before and after the captured Group.



Now 'oops' will be in Group 2.






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%2f53505091%2fhow-to-capture-group-within-capture-group%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









    1














    You may use



    (?:G(?!A)|()[^()]*?Koops


    Or, if you must check for the closing parentheses, add a lookahead at the end:



    (?:G(?!A)|()[^()]*?Koops(?=[^()]*))


    See the regex demo.



    Details





    • (?:G(?!A)|() - ( or end of the previous match (G(?!A))


    • [^()]*? - any 0+ chars other than ( and )


    • K - match reset operator


    • oops - the word you need (wrap with b if you need a whole word match)


    • (?=[^()]*)) - a positive lookahead that requires 0+ chars other than ( and ) up to the first ) to appear immediately to the right of the current location.






    share|improve this answer
























    • thank you very much. You made me study regular espressions in more detail. thanks again.

      – Alexander
      Nov 28 '18 at 8:39
















    1














    You may use



    (?:G(?!A)|()[^()]*?Koops


    Or, if you must check for the closing parentheses, add a lookahead at the end:



    (?:G(?!A)|()[^()]*?Koops(?=[^()]*))


    See the regex demo.



    Details





    • (?:G(?!A)|() - ( or end of the previous match (G(?!A))


    • [^()]*? - any 0+ chars other than ( and )


    • K - match reset operator


    • oops - the word you need (wrap with b if you need a whole word match)


    • (?=[^()]*)) - a positive lookahead that requires 0+ chars other than ( and ) up to the first ) to appear immediately to the right of the current location.






    share|improve this answer
























    • thank you very much. You made me study regular espressions in more detail. thanks again.

      – Alexander
      Nov 28 '18 at 8:39














    1












    1








    1







    You may use



    (?:G(?!A)|()[^()]*?Koops


    Or, if you must check for the closing parentheses, add a lookahead at the end:



    (?:G(?!A)|()[^()]*?Koops(?=[^()]*))


    See the regex demo.



    Details





    • (?:G(?!A)|() - ( or end of the previous match (G(?!A))


    • [^()]*? - any 0+ chars other than ( and )


    • K - match reset operator


    • oops - the word you need (wrap with b if you need a whole word match)


    • (?=[^()]*)) - a positive lookahead that requires 0+ chars other than ( and ) up to the first ) to appear immediately to the right of the current location.






    share|improve this answer













    You may use



    (?:G(?!A)|()[^()]*?Koops


    Or, if you must check for the closing parentheses, add a lookahead at the end:



    (?:G(?!A)|()[^()]*?Koops(?=[^()]*))


    See the regex demo.



    Details





    • (?:G(?!A)|() - ( or end of the previous match (G(?!A))


    • [^()]*? - any 0+ chars other than ( and )


    • K - match reset operator


    • oops - the word you need (wrap with b if you need a whole word match)


    • (?=[^()]*)) - a positive lookahead that requires 0+ chars other than ( and ) up to the first ) to appear immediately to the right of the current location.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 28 '18 at 8:15









    Wiktor StribiżewWiktor Stribiżew

    321k16141223




    321k16141223













    • thank you very much. You made me study regular espressions in more detail. thanks again.

      – Alexander
      Nov 28 '18 at 8:39



















    • thank you very much. You made me study regular espressions in more detail. thanks again.

      – Alexander
      Nov 28 '18 at 8:39

















    thank you very much. You made me study regular espressions in more detail. thanks again.

    – Alexander
    Nov 28 '18 at 8:39





    thank you very much. You made me study regular espressions in more detail. thanks again.

    – Alexander
    Nov 28 '18 at 8:39













    0














    You can use the following regex:



    (?<=()([wW]*?(oops)[wW]*?)(?=))


    Basically it injects a Group looking for 'oops' then it doubles the '[wW]*?' matching both before and after the captured Group.



    Now 'oops' will be in Group 2.






    share|improve this answer




























      0














      You can use the following regex:



      (?<=()([wW]*?(oops)[wW]*?)(?=))


      Basically it injects a Group looking for 'oops' then it doubles the '[wW]*?' matching both before and after the captured Group.



      Now 'oops' will be in Group 2.






      share|improve this answer


























        0












        0








        0







        You can use the following regex:



        (?<=()([wW]*?(oops)[wW]*?)(?=))


        Basically it injects a Group looking for 'oops' then it doubles the '[wW]*?' matching both before and after the captured Group.



        Now 'oops' will be in Group 2.






        share|improve this answer













        You can use the following regex:



        (?<=()([wW]*?(oops)[wW]*?)(?=))


        Basically it injects a Group looking for 'oops' then it doubles the '[wW]*?' matching both before and after the captured Group.



        Now 'oops' will be in Group 2.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 27 '18 at 17:39









        Poul BakPoul Bak

        5,48831233




        5,48831233






























            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%2f53505091%2fhow-to-capture-group-within-capture-group%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

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)