• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regex question  RSS feed

 
Matt Kidd
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 37496
547
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about this?



I changed your dot (match any character) to matching any characters followed by a single quote followed by any characters.
 
Matt Kidd
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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- .\\/']*)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!