473,325 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Regexp fails to return matches

Hi there,

I'm attempting to extract a number from a string, and I'm using the
following code:
Regex prRegexp = new Regex( @"Rank_1:\d+:(\d+)" );
MatchCollection matches = prRegexp.Matches( responseText.ToString() );
responseText.ToString() evaluates to "\n\nRank_1:1:4\n\n"

I'm only getting one match back, in the matches collection. The value
of this is the whole string.

I'd expect to get a second match which contains the final digit (4),
but this doesn't appear

Any ideas, folks? I'd appreciate some help on this

Regards

Chris Beach

Nov 17 '05 #1
4 1580
Aha!

I've solved my own problem - I wasn't using the Groups property of the
Match object. The following code works:

Regex prRegexp = new Regex( @"Rank_1:\d+:(\d+)" );
MatchCollection matches = prRegexp.Matches( responseText.ToString() );
if ( matches.Count < 1 || matches[0].Groups.Count < 2 )
throw new Exception( "No Pagerank found for " + url + ". The response
was invalid" );
else
pr = Convert.ToInt32( matches[0].Groups[1].Value );

Nov 17 '05 #2
Aha!

I've solved my own problem - I wasn't using the Groups property of the
Match object. The following code works:

Regex prRegexp = new Regex( @"Rank_1:\d+:(\d+)" );
MatchCollection matches = prRegexp.Matches( responseText.ToString() );
if ( matches.Count < 1 || matches[0].Groups.Count < 2 )
throw new Exception( "No Pagerank found for " + url + ". The response
was invalid" );
else
pr = Convert.ToInt32( matches[0].Groups[1].Value );

Nov 17 '05 #3
> Aha!

I've solved my own problem - I wasn't using the Groups property of the
Match object. The following code works:

Regex prRegexp = new Regex( @"Rank_1:\d+:(\d+)" );
MatchCollection matches = prRegexp.Matches( responseText.ToString() );
if ( matches.Count < 1 || matches[0].Groups.Count < 2 )
throw new Exception( "No Pagerank found for " + url + ". The response
was invalid" );
else
pr = Convert.ToInt32( matches[0].Groups[1].Value );


Find out more about Match, Group and Capture at
http://www.geekswithblogs.net/rahul/.../16/50330.aspx

--
Cheers,
Rahul Anand
Nov 17 '05 #4
> Aha!

I've solved my own problem - I wasn't using the Groups property of the
Match object. The following code works:

Regex prRegexp = new Regex( @"Rank_1:\d+:(\d+)" );
MatchCollection matches = prRegexp.Matches( responseText.ToString() );
if ( matches.Count < 1 || matches[0].Groups.Count < 2 )
throw new Exception( "No Pagerank found for " + url + ". The response
was invalid" );
else
pr = Convert.ToInt32( matches[0].Groups[1].Value );


Find out more about Match, Group and Capture at
http://www.geekswithblogs.net/rahul/.../16/50330.aspx

--
Cheers,
Rahul Anand
Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Andrew DeFaria | last post by:
I was reading my O'Reilly JavaScript The Definitive Guide when I came across RegExp and thought I could tighten up my JavaScript code that checks for a valid email address. Why does the following...
0
by: Chris Beach | last post by:
Hi there, I'm attempting to extract a number from a string, and I'm using the following code: Regex prRegexp = new Regex( @"Rank_1:\d+:(\d+)" ); MatchCollection matches = prRegexp.Matches(...
8
by: John Hazen | last post by:
I want to match one or two instances of a pattern in a string. According to the docs for the 're' module ( http://python.org/doc/current/lib/re-syntax.html ) the '?' qualifier is greedy by...
7
by: iannorton | last post by:
Hi, I'm trying to write a RegExp that will return search an array and return the closest 10 matches, for example, if i entered "Hel" and my array contained "Hello", "Hell", it would return Hello...
6
by: Christoph | last post by:
I'm trying to set up client side validation for a textarea form element to ensure that the data entered does not exceed 200 characters. I'm using the following code but it doesn't seem to be...
7
by: Csaba Gabor | last post by:
I need to come up with a function function regExpPos (text, re, parenNum) { ... } that will return the position within text of RegExp.$parenNum if there is a match, and -1 otherwise. For...
6
by: Christian Sonne | last post by:
Long story short, I'm trying to find all ISBN-10 numbers in a multiline string (approximately 10 pages of a normal book), and as far as I can tell, the *correct* thing to match would be this:...
5
by: gentsquash | last post by:
In a setting where I can specify only a JS regular expression, but not the JS code that will use it, I seek a regexp component that matches a string of letters, ignoring case. E.g, for "cat" I'd...
2
by: pjacobi.de | last post by:
Dear All, I'm looking for a function which, given a regexp re and and a string str, returns whether re won't match any string starting with str. (so it would always return False if str is ""...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.