Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

RegExp Question (java.util.regex )  RSS feed

 
Jessica Doe
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • 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 ]
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • 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
  • 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: 42970
73
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!