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

Reg expression to get a string starting from particular string

I’m trying to write a regular expression which returns a string after a particular string.

For example:
The string is

"<https://meraki/api/v1/sm/devices?fields%5B%5D=imei%2Ciccid%2ClastConnected%2CownerEmail%2C+ownerUsername%2CphoneNumber&perPage=1000&startingAfter=0>; rel=first"

result I’m expecting is — first.

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

Here is the expression i’m using

(?<=rel=\s").*(?=\)

>Solution :

Okay so this should work:

(?<=rel[=])[^"]*

I would advise looking over the syntax of regex again, because yours was not even matching the colons correctly. Look behinds (?<=pattern) match before the pattern you want to capture. Likewise look aheads (?=pattern) match after the pattern.

You can test your regex online here (or many other sites). They will show you the matching groups and errors, but will also explain what certain parts of the pattern do.

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