Regular Expressions Help

  • Thread starter Thread starter Guest 20221009
  • Start date Start date
G

Guest 20221009

Guest
Hi all,

Need help with Regex in C#, this a bit foreign to me. Need to retrieve First names from a table row with lost of junk in it and I cant seem to get my regex to match.

First Name : rba
c : sd
Company Name : asdfasdf
Email : [email protected]
Cellphone : 2323
Work phone : 2323

Using Rad Regex Designer, I came up with "First Name : (.*)\r\s". It validates, but when I use it in a console app nothing happens..

Please help :confused::confused:
 
Whenever I hear regular expressions it makes me think of this :D

Sorry that's all I have to offer...
 
lol :D ...its hopeless. I need to get this done before 13:00 and our main dev is on leave today..ARRRG!
 
Hi all,

Need help with Regex in C#, this a bit foreign to me. Need to retrieve First names from a table row with lost of junk in it and I cant seem to get my regex to match.



Using Rad Regex Designer, I came up with "First Name : (.*)\r\s". It validates, but when I use it in a console app nothing happens..

Please help :confused::confused:

What's the code you use in the console app to match the expression?
 
What's the code you use in the console app to match the expression?


Regex r;
Match m;

string st = "First Name : reba" ;

r = new Regex(@"First Name : (.*)\r\s",
RegexOptions.IgnoreCase);




for (m = r.Match(st); m.Success; m = m.NextMatch())
{
Console.WriteLine("Found href " + m.Groups[0] + " at "
+ m.Groups[0].Index);
}

I just dont get it.. all the examples I have seen dont make any sense.
 
I just dont get it.. all the examples I have seen dont make any sense.

The problem is that you test string does not contain any whitespace or carriage returns after the name string. Your regular expression expects a string in the following format:

First[SPACE]Name[SPACE]:[SPACE][ANY STRING VALUE][CARRIAGE RETURN][WHITE SPACE]

Try modifying it to:

First Name : (.*)\r*\s*

That will allow it to match the first name with or without a carriage return and whitespace after it... ;)
 
The problem is that you test string does not contain any whitespace or carriage returns after the name string. Your regular expression expects a string in the following format:

First[SPACE]Name[SPACE]:[SPACE][ANY STRING VALUE][CARRIAGE RETURN][WHITE SPACE]

Try modifying it to:

First Name : (.*)\r*\s*

That will allow it to match the first name with or without a carriage return and whitespace after it... ;)


Many thanks..it worked. Phew! :D
 
Top
Sign up to the MyBroadband newsletter
X