Ignoring apostrophe while capturing contents in single quotes REGEX2019 Community Moderator ElectionWhat is the difference between single-quoted and double-quoted strings in PHP?Reference — What does this symbol mean in PHP?Regex - non-capturing condition in larger captureRefine regex to distinguish between captchure group quotesREGEX to capture sentences with quotesRegex Capture Groups in C#JS RegEx replacement of a non-captured group?Distinguish quotes ' and apostrophes while tokenizing with regexRegex to find pattern NOT enclosed in quotesRepeat Capture Regex

Getting the || sign while using Kurier

Are small insurances worth it?

What is Tony Stark injecting into himself in Iron Man 3?

What is better: yes / no radio, or simple checkbox?

Finitely many repeated replacements

MySQL importing CSV files really slow

I reported the illegal activity of my boss to his boss. My boss found out. Now I am being punished. What should I do?

Can the alpha, lambda values of a glmnet object output determine whether ridge or Lasso?

Shifting between bemols (flats) and diesis (sharps)in the key signature

How to write a chaotic neutral protagonist and prevent my readers from thinking they are evil?

Why is a very small peak with larger m/z not considered to be the molecular ion?

Are there historical instances of the capital of a colonising country being temporarily or permanently shifted to one of its colonies?

Why couldn't the separatists legally leave the Republic?

Power Strip for Europe

Expressing logarithmic equations without logs

Why does cron require MTA for logging?

From an axiomatic set theoric approach why can we take uncountable unions?

Virginia employer terminated employee and wants signing bonus returned

Has a sovereign Communist government ever run, and conceded loss, on a fair election?

Minimizing with differential evolution

How does Ehrenfest's theorem apply to the quantum harmonic oscillator?

Is a piano played in the same way as a harmonium?

Proving a statement about real numbers

What is the generally accepted pronunciation of “topoi”?



Ignoring apostrophe while capturing contents in single quotes REGEX



2019 Community Moderator ElectionWhat is the difference between single-quoted and double-quoted strings in PHP?Reference — What does this symbol mean in PHP?Regex - non-capturing condition in larger captureRefine regex to distinguish between captchure group quotesREGEX to capture sentences with quotesRegex Capture Groups in C#JS RegEx replacement of a non-captured group?Distinguish quotes ' and apostrophes while tokenizing with regexRegex to find pattern NOT enclosed in quotesRepeat Capture Regex










0















The issue for me here is to capture the content inside single quotes(like 'xyz').

But the apostrophe which is the same symbol as a single quote(') is coming in the way!



The regex I've written is : /(w'w)(*SKIP)(*F)|('[^']*')/



The example i have used is : Hello ma'am 'This is Prashanth's book.'



What needs to be captured is : 'This is Prashanth's book.'.



But, what's capured is : 'This is Prashanth'!



Here is the link of what i tried on online regex tester



Any help is greatly appreciated. Thank you!










share|improve this question


























    0















    The issue for me here is to capture the content inside single quotes(like 'xyz').

    But the apostrophe which is the same symbol as a single quote(') is coming in the way!



    The regex I've written is : /(w'w)(*SKIP)(*F)|('[^']*')/



    The example i have used is : Hello ma'am 'This is Prashanth's book.'



    What needs to be captured is : 'This is Prashanth's book.'.



    But, what's capured is : 'This is Prashanth'!



    Here is the link of what i tried on online regex tester



    Any help is greatly appreciated. Thank you!










    share|improve this question
























      0












      0








      0








      The issue for me here is to capture the content inside single quotes(like 'xyz').

      But the apostrophe which is the same symbol as a single quote(') is coming in the way!



      The regex I've written is : /(w'w)(*SKIP)(*F)|('[^']*')/



      The example i have used is : Hello ma'am 'This is Prashanth's book.'



      What needs to be captured is : 'This is Prashanth's book.'.



      But, what's capured is : 'This is Prashanth'!



      Here is the link of what i tried on online regex tester



      Any help is greatly appreciated. Thank you!










      share|improve this question














      The issue for me here is to capture the content inside single quotes(like 'xyz').

      But the apostrophe which is the same symbol as a single quote(') is coming in the way!



      The regex I've written is : /(w'w)(*SKIP)(*F)|('[^']*')/



      The example i have used is : Hello ma'am 'This is Prashanth's book.'



      What needs to be captured is : 'This is Prashanth's book.'.



      But, what's capured is : 'This is Prashanth'!



      Here is the link of what i tried on online regex tester



      Any help is greatly appreciated. Thank you!







      php regex pcre






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 5:18









      Prashanth BennyPrashanth Benny

      1,2061225




      1,2061225






















          2 Answers
          2






          active

          oldest

          votes


















          1














          You can't use [^'] to capture a text that contains ' with in and in your example, This is Prashanth's book. contains a ' character within the text. You need to modify your regex to use .*? instead of [^'] and can write your regex as this,



          (w'w)(*SKIP)(*F)|('.*?'B)


          Demo with your updated regex



          Also, you don't need to escape a single quote ' as that has no special meaning in regex.



          From your example, it is not clear whether you want the captured match to contain ' around the match or not. In case you don't want ' to be captured in the match, you can use a lookarounds based regex and use this,



          (?<=B').*?(?='B)


          Explanation of regex:




          • (?<=B') - This positive look behind ensures what gets captured in match is preceded by a single quote which is not preceded by a word character which is ensured by B


          • .*? - Captures the text in non-greedy manner


          • (?='B) - Ensures the matched text is followed by a single quote and B ensures it doesn't match a quote that is immediately followed by any word character. E.g. it won't match an ending quote like 's

          Demo






          share|improve this answer




















          • 1





            Thanks @Pushpesh! working like a charm... :)

            – Prashanth Benny
            Mar 7 at 6:24







          • 1





            Pleased to help :)

            – Pushpesh Kumar Rajwanshi
            Mar 7 at 6:25






          • 1





            did you downvote the question? Someone did! I dont undestand why! :(

            – Prashanth Benny
            Mar 7 at 6:26






          • 1





            @PrashanthBenny: No I didn't downvote. Why would I answer a question if I downvoted. Also, getting downvotes on questions in regex tag is a normal trend. Anyway, take my upvote as your question is good and you showed what you tried with samples.

            – Pushpesh Kumar Rajwanshi
            Mar 7 at 6:28






          • 1





            Thank you so very much for your support Pushpesh. This just saved my day from being screwed up with this issue... I had not actually looked at B as a possibility at all :D

            – Prashanth Benny
            Mar 7 at 9:58


















          1














          For the string you have provided, you can use the regex:



          B'K(?:(?!'B).)+


          Click for Demo



          Explanation:




          • B - a non-word boundary


          • ' - matches a '


          • K - forget everything matched so far


          • (?:(?!'B).)+ - matches 1+ occurrences of any character(except newline) which does not start with ' followed by a non-word boundary





          share|improve this answer


















          • 1





            Wow, K. Didn't know about it for years... Thanks!

            – 1234ru
            Mar 7 at 12:23










          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%2f55036563%2fignoring-apostrophe-while-capturing-contents-in-single-quotes-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









          1














          You can't use [^'] to capture a text that contains ' with in and in your example, This is Prashanth's book. contains a ' character within the text. You need to modify your regex to use .*? instead of [^'] and can write your regex as this,



          (w'w)(*SKIP)(*F)|('.*?'B)


          Demo with your updated regex



          Also, you don't need to escape a single quote ' as that has no special meaning in regex.



          From your example, it is not clear whether you want the captured match to contain ' around the match or not. In case you don't want ' to be captured in the match, you can use a lookarounds based regex and use this,



          (?<=B').*?(?='B)


          Explanation of regex:




          • (?<=B') - This positive look behind ensures what gets captured in match is preceded by a single quote which is not preceded by a word character which is ensured by B


          • .*? - Captures the text in non-greedy manner


          • (?='B) - Ensures the matched text is followed by a single quote and B ensures it doesn't match a quote that is immediately followed by any word character. E.g. it won't match an ending quote like 's

          Demo






          share|improve this answer




















          • 1





            Thanks @Pushpesh! working like a charm... :)

            – Prashanth Benny
            Mar 7 at 6:24







          • 1





            Pleased to help :)

            – Pushpesh Kumar Rajwanshi
            Mar 7 at 6:25






          • 1





            did you downvote the question? Someone did! I dont undestand why! :(

            – Prashanth Benny
            Mar 7 at 6:26






          • 1





            @PrashanthBenny: No I didn't downvote. Why would I answer a question if I downvoted. Also, getting downvotes on questions in regex tag is a normal trend. Anyway, take my upvote as your question is good and you showed what you tried with samples.

            – Pushpesh Kumar Rajwanshi
            Mar 7 at 6:28






          • 1





            Thank you so very much for your support Pushpesh. This just saved my day from being screwed up with this issue... I had not actually looked at B as a possibility at all :D

            – Prashanth Benny
            Mar 7 at 9:58















          1














          You can't use [^'] to capture a text that contains ' with in and in your example, This is Prashanth's book. contains a ' character within the text. You need to modify your regex to use .*? instead of [^'] and can write your regex as this,



          (w'w)(*SKIP)(*F)|('.*?'B)


          Demo with your updated regex



          Also, you don't need to escape a single quote ' as that has no special meaning in regex.



          From your example, it is not clear whether you want the captured match to contain ' around the match or not. In case you don't want ' to be captured in the match, you can use a lookarounds based regex and use this,



          (?<=B').*?(?='B)


          Explanation of regex:




          • (?<=B') - This positive look behind ensures what gets captured in match is preceded by a single quote which is not preceded by a word character which is ensured by B


          • .*? - Captures the text in non-greedy manner


          • (?='B) - Ensures the matched text is followed by a single quote and B ensures it doesn't match a quote that is immediately followed by any word character. E.g. it won't match an ending quote like 's

          Demo






          share|improve this answer




















          • 1





            Thanks @Pushpesh! working like a charm... :)

            – Prashanth Benny
            Mar 7 at 6:24







          • 1





            Pleased to help :)

            – Pushpesh Kumar Rajwanshi
            Mar 7 at 6:25






          • 1





            did you downvote the question? Someone did! I dont undestand why! :(

            – Prashanth Benny
            Mar 7 at 6:26






          • 1





            @PrashanthBenny: No I didn't downvote. Why would I answer a question if I downvoted. Also, getting downvotes on questions in regex tag is a normal trend. Anyway, take my upvote as your question is good and you showed what you tried with samples.

            – Pushpesh Kumar Rajwanshi
            Mar 7 at 6:28






          • 1





            Thank you so very much for your support Pushpesh. This just saved my day from being screwed up with this issue... I had not actually looked at B as a possibility at all :D

            – Prashanth Benny
            Mar 7 at 9:58













          1












          1








          1







          You can't use [^'] to capture a text that contains ' with in and in your example, This is Prashanth's book. contains a ' character within the text. You need to modify your regex to use .*? instead of [^'] and can write your regex as this,



          (w'w)(*SKIP)(*F)|('.*?'B)


          Demo with your updated regex



          Also, you don't need to escape a single quote ' as that has no special meaning in regex.



          From your example, it is not clear whether you want the captured match to contain ' around the match or not. In case you don't want ' to be captured in the match, you can use a lookarounds based regex and use this,



          (?<=B').*?(?='B)


          Explanation of regex:




          • (?<=B') - This positive look behind ensures what gets captured in match is preceded by a single quote which is not preceded by a word character which is ensured by B


          • .*? - Captures the text in non-greedy manner


          • (?='B) - Ensures the matched text is followed by a single quote and B ensures it doesn't match a quote that is immediately followed by any word character. E.g. it won't match an ending quote like 's

          Demo






          share|improve this answer















          You can't use [^'] to capture a text that contains ' with in and in your example, This is Prashanth's book. contains a ' character within the text. You need to modify your regex to use .*? instead of [^'] and can write your regex as this,



          (w'w)(*SKIP)(*F)|('.*?'B)


          Demo with your updated regex



          Also, you don't need to escape a single quote ' as that has no special meaning in regex.



          From your example, it is not clear whether you want the captured match to contain ' around the match or not. In case you don't want ' to be captured in the match, you can use a lookarounds based regex and use this,



          (?<=B').*?(?='B)


          Explanation of regex:




          • (?<=B') - This positive look behind ensures what gets captured in match is preceded by a single quote which is not preceded by a word character which is ensured by B


          • .*? - Captures the text in non-greedy manner


          • (?='B) - Ensures the matched text is followed by a single quote and B ensures it doesn't match a quote that is immediately followed by any word character. E.g. it won't match an ending quote like 's

          Demo







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 7 at 5:36

























          answered Mar 7 at 5:24









          Pushpesh Kumar RajwanshiPushpesh Kumar Rajwanshi

          9,28321029




          9,28321029







          • 1





            Thanks @Pushpesh! working like a charm... :)

            – Prashanth Benny
            Mar 7 at 6:24







          • 1





            Pleased to help :)

            – Pushpesh Kumar Rajwanshi
            Mar 7 at 6:25






          • 1





            did you downvote the question? Someone did! I dont undestand why! :(

            – Prashanth Benny
            Mar 7 at 6:26






          • 1





            @PrashanthBenny: No I didn't downvote. Why would I answer a question if I downvoted. Also, getting downvotes on questions in regex tag is a normal trend. Anyway, take my upvote as your question is good and you showed what you tried with samples.

            – Pushpesh Kumar Rajwanshi
            Mar 7 at 6:28






          • 1





            Thank you so very much for your support Pushpesh. This just saved my day from being screwed up with this issue... I had not actually looked at B as a possibility at all :D

            – Prashanth Benny
            Mar 7 at 9:58












          • 1





            Thanks @Pushpesh! working like a charm... :)

            – Prashanth Benny
            Mar 7 at 6:24







          • 1





            Pleased to help :)

            – Pushpesh Kumar Rajwanshi
            Mar 7 at 6:25






          • 1





            did you downvote the question? Someone did! I dont undestand why! :(

            – Prashanth Benny
            Mar 7 at 6:26






          • 1





            @PrashanthBenny: No I didn't downvote. Why would I answer a question if I downvoted. Also, getting downvotes on questions in regex tag is a normal trend. Anyway, take my upvote as your question is good and you showed what you tried with samples.

            – Pushpesh Kumar Rajwanshi
            Mar 7 at 6:28






          • 1





            Thank you so very much for your support Pushpesh. This just saved my day from being screwed up with this issue... I had not actually looked at B as a possibility at all :D

            – Prashanth Benny
            Mar 7 at 9:58







          1




          1





          Thanks @Pushpesh! working like a charm... :)

          – Prashanth Benny
          Mar 7 at 6:24






          Thanks @Pushpesh! working like a charm... :)

          – Prashanth Benny
          Mar 7 at 6:24





          1




          1





          Pleased to help :)

          – Pushpesh Kumar Rajwanshi
          Mar 7 at 6:25





          Pleased to help :)

          – Pushpesh Kumar Rajwanshi
          Mar 7 at 6:25




          1




          1





          did you downvote the question? Someone did! I dont undestand why! :(

          – Prashanth Benny
          Mar 7 at 6:26





          did you downvote the question? Someone did! I dont undestand why! :(

          – Prashanth Benny
          Mar 7 at 6:26




          1




          1





          @PrashanthBenny: No I didn't downvote. Why would I answer a question if I downvoted. Also, getting downvotes on questions in regex tag is a normal trend. Anyway, take my upvote as your question is good and you showed what you tried with samples.

          – Pushpesh Kumar Rajwanshi
          Mar 7 at 6:28





          @PrashanthBenny: No I didn't downvote. Why would I answer a question if I downvoted. Also, getting downvotes on questions in regex tag is a normal trend. Anyway, take my upvote as your question is good and you showed what you tried with samples.

          – Pushpesh Kumar Rajwanshi
          Mar 7 at 6:28




          1




          1





          Thank you so very much for your support Pushpesh. This just saved my day from being screwed up with this issue... I had not actually looked at B as a possibility at all :D

          – Prashanth Benny
          Mar 7 at 9:58





          Thank you so very much for your support Pushpesh. This just saved my day from being screwed up with this issue... I had not actually looked at B as a possibility at all :D

          – Prashanth Benny
          Mar 7 at 9:58













          1














          For the string you have provided, you can use the regex:



          B'K(?:(?!'B).)+


          Click for Demo



          Explanation:




          • B - a non-word boundary


          • ' - matches a '


          • K - forget everything matched so far


          • (?:(?!'B).)+ - matches 1+ occurrences of any character(except newline) which does not start with ' followed by a non-word boundary





          share|improve this answer


















          • 1





            Wow, K. Didn't know about it for years... Thanks!

            – 1234ru
            Mar 7 at 12:23















          1














          For the string you have provided, you can use the regex:



          B'K(?:(?!'B).)+


          Click for Demo



          Explanation:




          • B - a non-word boundary


          • ' - matches a '


          • K - forget everything matched so far


          • (?:(?!'B).)+ - matches 1+ occurrences of any character(except newline) which does not start with ' followed by a non-word boundary





          share|improve this answer


















          • 1





            Wow, K. Didn't know about it for years... Thanks!

            – 1234ru
            Mar 7 at 12:23













          1












          1








          1







          For the string you have provided, you can use the regex:



          B'K(?:(?!'B).)+


          Click for Demo



          Explanation:




          • B - a non-word boundary


          • ' - matches a '


          • K - forget everything matched so far


          • (?:(?!'B).)+ - matches 1+ occurrences of any character(except newline) which does not start with ' followed by a non-word boundary





          share|improve this answer













          For the string you have provided, you can use the regex:



          B'K(?:(?!'B).)+


          Click for Demo



          Explanation:




          • B - a non-word boundary


          • ' - matches a '


          • K - forget everything matched so far


          • (?:(?!'B).)+ - matches 1+ occurrences of any character(except newline) which does not start with ' followed by a non-word boundary






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 7 at 5:24









          PotatoPotato

          7,76321133




          7,76321133







          • 1





            Wow, K. Didn't know about it for years... Thanks!

            – 1234ru
            Mar 7 at 12:23












          • 1





            Wow, K. Didn't know about it for years... Thanks!

            – 1234ru
            Mar 7 at 12:23







          1




          1





          Wow, K. Didn't know about it for years... Thanks!

          – 1234ru
          Mar 7 at 12:23





          Wow, K. Didn't know about it for years... Thanks!

          – 1234ru
          Mar 7 at 12:23

















          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%2f55036563%2fignoring-apostrophe-while-capturing-contents-in-single-quotes-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

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

          Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

          2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived