Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get strings after specific patterns

I have strings that looks like this:

searchUniqueCode("name", "FF14_1451_DAD4");searchUniqueCode("name", "F1F1_1451_DAD4");
searchUniqueCode("name", "FF14_3121_DAD4");searchUniqueCode("name", "SH14_1451_DAD4");
searchUniqueCode("name", "FF14_1131_DAD4");searchUniqueCode("name", "FF14_1451_D31F");

And I am trying to get all of the strings under " " after the common pattern searchUniqueCode("name", Like the FF14_1451_DAD4.

Is there any way I can achieve that using PHP?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thank you!

>Solution :

Try this regex:

searchUniqueCode\("name",\s*"\K[^"]+

Click for Demo

Check code here


Explanation:

  • searchUniqueCode\("name", – matches searchUniqueCode\("name",
  • \s*" – matches 0 or more occurrences of a white-space followed by a "
  • \K – un-matches whatever has been matched so far and starts the match from the current position
  • [^"]+ – matches 1 or more occurrences of any character that is not a ". This is the desired match that will match everything until the next occurrence of "

Or

You can capture the desired values in group 1 as shown below:

searchUniqueCode\("name",\s*"([^"]+)"Working code here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading