Confused about Regular Expressions
I am using the Regular Expression class to parse a string. I downloaded a RE tester which seems to be working fine.
The problem I am finding is that my regular expressions do not evaluate properly when I switch the order.
For example:
(?[0-9]+)|(?[a-zA-Z_$][a-zA-Z0-9_$]*)|(?\s*)
finds the integers
but if I move it to the end, it does not:
(?[a-zA-Z_$][a-zA-Z0-9_$]*)|(?\s*)|(?[0-9]+)
Are there ordering rules?
Kirtan PatelPosted Aug 21, 2009, 9:45 AM
you can detect Integers From Mixed Data By Following Simple RegEx
[0-9]*
Dont go for that Complected Syntax Below is Example How I parsed Integers From Mixed String ( Numbers + Alphabets)
dont forget to mark "Do you like answer" it will give me some credits :)
private void btnDetectNumbers_Click(object sender, EventArgs e)
{
Regex re = new Regex("[0-9]*");
MatchCollection mc = re.Matches(textBox1.Text.Trim());
foreach (Match m in mc)
{
if (m.ToString().Trim() != "")
{
listBox1.Items.Add(m.ToString());
}
}
}