• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get multiple regex matches

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am strugling to get all the strings which are between $[..] from the below URL using regex.

url=http://xyz.com/destination/woe_$[woeid];fields=overview/photos;count=$[photoCount],refiners?raw_query=$[rawQuery]&country=$[countryCode]&city=$[city]

i wrote the below regex prgram in java but no luck.


I got the below result for the above program.

1
[woeid]
woeid

can you please help me here to get the following strings from the above url using regex.

woeid
photoCount
rawQuery
countryCode
city

Thanks, Gopi
 
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It isn't easy writing regular expressions. However I have come up with a solution for your problem.
 
Saloon Keeper
Posts: 7594
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
m.find() finds the next match, if any. If you want more than one match, you need to call it more than once, possibly in a while loop.
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Replace the if condition with while as below


The output is



Can you try a little bit to remove the '[' and ']'
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yikes That's three replies @ 16:35
 
Gopi Chella
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
was frustrated with this issue, now its good to know the mistake i have done ....you guys are Rocking stars !!!

My Special thanks to Harsha Smith

Marking this post status as resolved.

~Gopi
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic