Reputation: 3760
I have to replace the following in a NSURL:
a_token=lksjadfkj%2gf98273984
with
a_token=new_token
a token can be in the follwing forms:
a_token=989asaofiusaodifusa9f789asdofu&lat=43.3
a_token=lksjadfkj%2gf98273984
So it either ends with & or end line/nothing.
How could I write the regex expression for it?
Thanks!
Upvotes: 0
Views: 82
Reputation: 6770
You could try:
[stringWithURL stringByReplacingOccurrencesOfRegex:@"(?<=a_token=)[^&]*"
withString:@"new_token"];
I haven't tested it. Basically, the regex uses a look-behind assertion to match a_token=
. The look-behind is not included in the text that is matched. Then, the regex matches "zero or more characters that aren't &
".
Upvotes: 0