lorenw — 2012-01-13T17:12:39-05:00 — #1
I'm trying to do a regex on a string, here is an excerpt,
...},"end_address":"1901 SE Port St. Main Blvd. Tampa, FL 34952","end_location" ...(data)... "end_location" ...(data)... "end_location"
This is the part that I want to target "end_address":"1901 SE Port St. Main Blvd. Tampa, FL 34952","end_location" so I can replace the address.
This is my regex
string = string.replace(/end_address.*end_location/, 'end_address":"1895 main street North","end_location');
It works but the problem is that the regex spans all end_location (there should be many end_location) and wipes out a huge chunk of data, this leaves only one end_location.
I just need to match the first occurrence of end_location and not the last occurrence of end_location.
scallioxtx — 2012-01-13T17:45:50-05:00 — #2
Isn't that JSON? If so, why not just use json_decode?
paul_wilkins — 2012-01-13T18:01:17-05:00 — #3
You can use ? to denote a non-greedy match, such as .*?
Details about how it works are found at http://www.regular-expressions.info/repeat.html
lorenw — 2012-01-13T18:08:51-05:00 — #4
@paul_wilkins Thank You, Thank You, Thank You, works a treat. Spent many hours on that.
@ScallioXTX I am using JSON.stringify(response); Its for the google maps response so I have a string that I need to work with.
Thanks to all.
system — 2014-10-07T21:46:26-04:00 — #5
This topic is now closed. New replies are no longer allowed.