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.

Here is the expression i’m using


>Solution :

Okay so this should work:


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.

Leave a Reply Cancel reply