| Author |
Regex question
|
Matt Kidd
Ranch Hand
Joined: Jul 17, 2002
Posts: 256
|
|
I've got a large json string that I need to replace the apostrophes within certain URLs. I can't do a wholesale replaceAll as I need some of the apostrophes to remain. So far this it the regex I have:
("photo": ")(.*?)(")
It matches:
"photo": "http:\/\/theastrologer.com\/matchme\/images\/photos\/Snoop Dogg.jpg"
and
"photo": "http:\/\/theastrologer.com\/matchme\/images\/photos\/Shaquille O'Neal.jpg"
but I only want it to match the 2nd. Any ideas?
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26193
|
|
How about this?
I changed your dot (match any character) to matching any characters followed by a single quote followed by any characters.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Matt Kidd
Ranch Hand
Joined: Jul 17, 2002
Posts: 256
|
|
Thanks. It's better but now, since there is another node in the json object containing the single quote, it's also being greedy before what should be the first "photo: " it encounters.
I guess ideally it should only get the first one. Hmmmm....
|
 |
Matt Kidd
Ranch Hand
Joined: Jul 17, 2002
Posts: 256
|
|
Getting closer....so far I can get all the urls that end with jpg however if I can I could improve it to only give me the ones with a single apostrophe that'd be better.
([\w- ]+\.)+[\w-]+(\\/[\w- .\\/']*)
|
 |
 |
|
|
subject: Regex question
|
|
|