473,386 Members | 1,706 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,386 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 1584
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.