Matching entire, multiline pattern, multiple times but not if match contains stringRegular expression to match a line that doesn't contain a wordRegEx match open tags except XHTML self-contained tagsRegEx - Exclude Matched PatternsNegative lookahead with capturing groupsRegex match a string that doesn't contains a stringRegular expression, match anything but these stringsConditional Regex for multiple matches in a lineHow to match string followed by repeated pattern in regex?Regex negative lookahead for url parameterregex look ahead behind (look around) negative problems

Why does Intel's Haswell chip allow FP multiplication to be twice as fast as addition?

Simple Stop watch which i want to extend

What game uses dice with sides powers of 2?

Best gun to modify into a monsterhunter weapon?

Wherein the Shatapatha Brahmana it was mentioned about 8.64 lakh alphabets in Vedas?

Who are these characters/superheroes in the posters from Chris's room in Family Guy?

How can you evade tax by getting employment income just in equity, then using this equity as collateral to take out loan?

Non-OR journals which regularly publish OR research

What does "sardine box" mean?

How to avoid the "need" to learn more before conducting research?

Word or idiom defining something barely functional

How to create all combinations from a nested list while preserving the structure using R?

Is TA-ing worth the opportunity cost?

Should you play baroque pieces a semitone lower?

Is Texas Instrument wrong with their pin number on TO-92 package?

Write an interpreter for *

What costs less energy? Roll or Yaw?

Why are Gatwick's runways too close together?

Trying to write a shell script that keeps testing a server remotely, but it keeps falling in else statement when I logout

Replace value with variable length between double quotes

Does this Foo machine halt?

Identification of vintage sloping window

What is the difference between 型 and 形?

Should RL rewards diminish over time?



Matching entire, multiline pattern, multiple times but not if match contains string


Regular expression to match a line that doesn't contain a wordRegEx match open tags except XHTML self-contained tagsRegEx - Exclude Matched PatternsNegative lookahead with capturing groupsRegex match a string that doesn't contains a stringRegular expression, match anything but these stringsConditional Regex for multiple matches in a lineHow to match string followed by repeated pattern in regex?Regex negative lookahead for url parameterregex look ahead behind (look around) negative problems






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-1















Imagine I have this text (I realise using regex to parse HTML is not the correct solution...)



 <div><p>HELLO1</p>
<span>SPIDER</span></div>
<div><p>HELLO2</p>
<span>CHEESE</span></div>
<div><p>HELLO3</p>
<span>BANANA</span></div>


I want to match text inside the <p> and <span> respectively (this is a contrived example)



I can achieve that by using:



/<p>(.*?)</p>.*?<span>(.*?)</span>.*?</div>/gsmi



However, I don't want to match if the text inside the span is CHEESE.
Ive tried to use a negative lookahead like so:



/<p>(.*?)</p>.*?<span>((?!CHEESE).*?)</span>.*?</div>/gsmi



However, that now matches the wrong thing as the pattern matches to HELLO2 and BANANA where I want HELLO3 and BANANA



I realise this is because Im using .*? but this is required for the real life solution.



Example here: https://regex101.com/r/h4YgDm/3



How can I match, a whole pattern only but still spanning multiple lines?










share|improve this question


























  • You have no <p> tag in your example.

    – Reymart Betana
    Mar 27 at 8:26











  • @ReymartBetana Thanks - I refactored example, whilst writing

    – Andrew Hall
    Mar 27 at 8:28

















-1















Imagine I have this text (I realise using regex to parse HTML is not the correct solution...)



 <div><p>HELLO1</p>
<span>SPIDER</span></div>
<div><p>HELLO2</p>
<span>CHEESE</span></div>
<div><p>HELLO3</p>
<span>BANANA</span></div>


I want to match text inside the <p> and <span> respectively (this is a contrived example)



I can achieve that by using:



/<p>(.*?)</p>.*?<span>(.*?)</span>.*?</div>/gsmi



However, I don't want to match if the text inside the span is CHEESE.
Ive tried to use a negative lookahead like so:



/<p>(.*?)</p>.*?<span>((?!CHEESE).*?)</span>.*?</div>/gsmi



However, that now matches the wrong thing as the pattern matches to HELLO2 and BANANA where I want HELLO3 and BANANA



I realise this is because Im using .*? but this is required for the real life solution.



Example here: https://regex101.com/r/h4YgDm/3



How can I match, a whole pattern only but still spanning multiple lines?










share|improve this question


























  • You have no <p> tag in your example.

    – Reymart Betana
    Mar 27 at 8:26











  • @ReymartBetana Thanks - I refactored example, whilst writing

    – Andrew Hall
    Mar 27 at 8:28













-1












-1








-1








Imagine I have this text (I realise using regex to parse HTML is not the correct solution...)



 <div><p>HELLO1</p>
<span>SPIDER</span></div>
<div><p>HELLO2</p>
<span>CHEESE</span></div>
<div><p>HELLO3</p>
<span>BANANA</span></div>


I want to match text inside the <p> and <span> respectively (this is a contrived example)



I can achieve that by using:



/<p>(.*?)</p>.*?<span>(.*?)</span>.*?</div>/gsmi



However, I don't want to match if the text inside the span is CHEESE.
Ive tried to use a negative lookahead like so:



/<p>(.*?)</p>.*?<span>((?!CHEESE).*?)</span>.*?</div>/gsmi



However, that now matches the wrong thing as the pattern matches to HELLO2 and BANANA where I want HELLO3 and BANANA



I realise this is because Im using .*? but this is required for the real life solution.



Example here: https://regex101.com/r/h4YgDm/3



How can I match, a whole pattern only but still spanning multiple lines?










share|improve this question
















Imagine I have this text (I realise using regex to parse HTML is not the correct solution...)



 <div><p>HELLO1</p>
<span>SPIDER</span></div>
<div><p>HELLO2</p>
<span>CHEESE</span></div>
<div><p>HELLO3</p>
<span>BANANA</span></div>


I want to match text inside the <p> and <span> respectively (this is a contrived example)



I can achieve that by using:



/<p>(.*?)</p>.*?<span>(.*?)</span>.*?</div>/gsmi



However, I don't want to match if the text inside the span is CHEESE.
Ive tried to use a negative lookahead like so:



/<p>(.*?)</p>.*?<span>((?!CHEESE).*?)</span>.*?</div>/gsmi



However, that now matches the wrong thing as the pattern matches to HELLO2 and BANANA where I want HELLO3 and BANANA



I realise this is because Im using .*? but this is required for the real life solution.



Example here: https://regex101.com/r/h4YgDm/3



How can I match, a whole pattern only but still spanning multiple lines?







regex regex-negation regex-lookarounds






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 8:34







Andrew Hall

















asked Mar 27 at 8:23









Andrew HallAndrew Hall

2,75415 silver badges29 bronze badges




2,75415 silver badges29 bronze badges















  • You have no <p> tag in your example.

    – Reymart Betana
    Mar 27 at 8:26











  • @ReymartBetana Thanks - I refactored example, whilst writing

    – Andrew Hall
    Mar 27 at 8:28

















  • You have no <p> tag in your example.

    – Reymart Betana
    Mar 27 at 8:26











  • @ReymartBetana Thanks - I refactored example, whilst writing

    – Andrew Hall
    Mar 27 at 8:28
















You have no <p> tag in your example.

– Reymart Betana
Mar 27 at 8:26





You have no <p> tag in your example.

– Reymart Betana
Mar 27 at 8:26













@ReymartBetana Thanks - I refactored example, whilst writing

– Andrew Hall
Mar 27 at 8:28





@ReymartBetana Thanks - I refactored example, whilst writing

– Andrew Hall
Mar 27 at 8:28












2 Answers
2






active

oldest

votes


















0














You could achieve what you want in two steps. First, extract the div elements which meet the criteria (ie. no CHEESE) like this (demo):



<div>(?:(?!CHEESE).)*?</div>


Second, select the content between p and span tags as two groups (demo):



(?<=<p>)(.*?)(?=</p>)(?:.*?)(?<=<span>)(.*?)(?=</span>)





share|improve this answer

























  • Is there anyway this can done in one step? Perhaps using back references?

    – Andrew Hall
    Mar 27 at 14:29












  • Not as far as I know.

    – glhr
    Mar 27 at 15:15


















0














A colleague of mine sent me this answer, which does what I want:



https://regex101.com/r/h4YgDm/8



Regex: (?:(?:<div><p>(w*)</p>s)(?!<span>CHEESE</span>)(?:<span>(w*)</span>)</div>)






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%2f55372631%2fmatching-entire-multiline-pattern-multiple-times-but-not-if-match-contains-str%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









    0














    You could achieve what you want in two steps. First, extract the div elements which meet the criteria (ie. no CHEESE) like this (demo):



    <div>(?:(?!CHEESE).)*?</div>


    Second, select the content between p and span tags as two groups (demo):



    (?<=<p>)(.*?)(?=</p>)(?:.*?)(?<=<span>)(.*?)(?=</span>)





    share|improve this answer

























    • Is there anyway this can done in one step? Perhaps using back references?

      – Andrew Hall
      Mar 27 at 14:29












    • Not as far as I know.

      – glhr
      Mar 27 at 15:15















    0














    You could achieve what you want in two steps. First, extract the div elements which meet the criteria (ie. no CHEESE) like this (demo):



    <div>(?:(?!CHEESE).)*?</div>


    Second, select the content between p and span tags as two groups (demo):



    (?<=<p>)(.*?)(?=</p>)(?:.*?)(?<=<span>)(.*?)(?=</span>)





    share|improve this answer

























    • Is there anyway this can done in one step? Perhaps using back references?

      – Andrew Hall
      Mar 27 at 14:29












    • Not as far as I know.

      – glhr
      Mar 27 at 15:15













    0












    0








    0







    You could achieve what you want in two steps. First, extract the div elements which meet the criteria (ie. no CHEESE) like this (demo):



    <div>(?:(?!CHEESE).)*?</div>


    Second, select the content between p and span tags as two groups (demo):



    (?<=<p>)(.*?)(?=</p>)(?:.*?)(?<=<span>)(.*?)(?=</span>)





    share|improve this answer













    You could achieve what you want in two steps. First, extract the div elements which meet the criteria (ie. no CHEESE) like this (demo):



    <div>(?:(?!CHEESE).)*?</div>


    Second, select the content between p and span tags as two groups (demo):



    (?<=<p>)(.*?)(?=</p>)(?:.*?)(?<=<span>)(.*?)(?=</span>)






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 27 at 13:27









    glhrglhr

    3,3231 gold badge9 silver badges21 bronze badges




    3,3231 gold badge9 silver badges21 bronze badges















    • Is there anyway this can done in one step? Perhaps using back references?

      – Andrew Hall
      Mar 27 at 14:29












    • Not as far as I know.

      – glhr
      Mar 27 at 15:15

















    • Is there anyway this can done in one step? Perhaps using back references?

      – Andrew Hall
      Mar 27 at 14:29












    • Not as far as I know.

      – glhr
      Mar 27 at 15:15
















    Is there anyway this can done in one step? Perhaps using back references?

    – Andrew Hall
    Mar 27 at 14:29






    Is there anyway this can done in one step? Perhaps using back references?

    – Andrew Hall
    Mar 27 at 14:29














    Not as far as I know.

    – glhr
    Mar 27 at 15:15





    Not as far as I know.

    – glhr
    Mar 27 at 15:15













    0














    A colleague of mine sent me this answer, which does what I want:



    https://regex101.com/r/h4YgDm/8



    Regex: (?:(?:<div><p>(w*)</p>s)(?!<span>CHEESE</span>)(?:<span>(w*)</span>)</div>)






    share|improve this answer





























      0














      A colleague of mine sent me this answer, which does what I want:



      https://regex101.com/r/h4YgDm/8



      Regex: (?:(?:<div><p>(w*)</p>s)(?!<span>CHEESE</span>)(?:<span>(w*)</span>)</div>)






      share|improve this answer



























        0












        0








        0







        A colleague of mine sent me this answer, which does what I want:



        https://regex101.com/r/h4YgDm/8



        Regex: (?:(?:<div><p>(w*)</p>s)(?!<span>CHEESE</span>)(?:<span>(w*)</span>)</div>)






        share|improve this answer













        A colleague of mine sent me this answer, which does what I want:



        https://regex101.com/r/h4YgDm/8



        Regex: (?:(?:<div><p>(w*)</p>s)(?!<span>CHEESE</span>)(?:<span>(w*)</span>)</div>)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 27 at 18:06









        Andrew HallAndrew Hall

        2,75415 silver badges29 bronze badges




        2,75415 silver badges29 bronze badges






























            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%2f55372631%2fmatching-entire-multiline-pattern-multiple-times-but-not-if-match-contains-str%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

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해