Regular Expressions.....

  • Thread starter Thread starter Alan Seunarayan
  • Start date Start date
A

Alan Seunarayan

Hello all,
I'm having a problem with regular expressions. I have a list of strings
with numeric values and I am trying to use reg exp to search through them.
if I have numbers 1 to 1001 and I want to find numbers that match ??9 how
can I get it working?

Thanks for your time!

Alan
 
I hope this code is going to show how to use Regex class:

string strRxPattern = "(?<number>\\d\\d9)";
StringBuilder sb = new StringBuilder ();
string strToCheck = "";

for (int i = 1; i <= 1001; i++)
sb.Append (i.ToString () + " ");
strToCheck = sb.ToString ();
Regex rx = new Regex (strRxPattern);

if (rx.IsMatch (strToCheck))
{
foreach (Match mt in rx.Matches (strToCheck))
{
Console.WriteLine (string.Format ("{0}", mt.Groups ["number"].Value));
}
}
Console.WriteLine ("Finished...");
Console.ReadLine ();
 
Thanks for your reply, however I should have elaborated a bit more.....

THE SCENARIO:
I have a ListView control with numerous columns and numerous
ListViewItems. I also have a "Find" dialog form that allows for users to
enter a search pattern. This pattern may be as follows....
12?999
12X999
Al?n*

etc...
I need a general purpose reg-ex to sort it out. I hope that you can help
again.

Many thanks,

Alan


message I hope this code is going to show how to use Regex class:

string strRxPattern = "(?<number>\\d\\d9)";
StringBuilder sb = new StringBuilder ();
string strToCheck = "";

for (int i = 1; i <= 1001; i++)
sb.Append (i.ToString () + " ");
strToCheck = sb.ToString ();
Regex rx = new Regex (strRxPattern);

if (rx.IsMatch (strToCheck))
{
foreach (Match mt in rx.Matches (strToCheck))
{
Console.WriteLine (string.Format ("{0}", mt.Groups ["number"].Value));
}
}
Console.WriteLine ("Finished...");
Console.ReadLine ();
 
Back
Top