• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Regex question

 
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author & internet detective
Posts: 41250
849
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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- .\\/']*)
 
If you are using a rototiller, you are doing it wrong. Even on this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic