Reg expression to get a string starting from particular string

Advertisements

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

(?<=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.

Leave a ReplyCancel reply