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

          Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

          Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

          How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page