• 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

RegExp Question (java.util.regex )

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

I am using this regex to locate a number:

/cdvd\+on\+order/1,1,(\d+)

But, there are 50 such numbers on the page--all identical. How do I tell it stop on the first one?

Thx!

Jessica Doe

[ January 06, 2006: Message edited by: Jessica Doe ]
[ January 06, 2006: Message edited by: Jessica Doe ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean by "stop"? This regexp would only match a single one. Are you processing the results in a loop, and need to break out of it after the first match?
 
Jessica Doe
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, when I try out my expression here:

http://www.regexlib.com/RETester.aspx

it lists 15 matches. So, I figured my code (below) was doing the same thing.

const string LAST_ON_ORDER_PAGE_NO = @"/cdvd\+on\+order/1,1,(\d+)";
Match match = Regex.Match ( pageContent, LAST_ON_ORDER_PAGE_NO, RegexOptions.IgnoreCase );
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, that just means that it matches at 15 different locations. Depending on which regexp library you use, there's always an option to iterate through all of them. Just stop after the first one
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic