aspose file tools
The moose likes Beginning Java and the fly likes Regex question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Regex question" Watch "Regex question" New topic
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
    
  66

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- .\\/']*)
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Regex question
 
Similar Threads
loading large image file
Overhead of displaying images
Retreiving photos from the photo gallery
how to read images from mobile photo gallery using Java script
bigger photo...but bigger image appear below smaller