Problem using multiple delimiters with regular expressions.

  • Thread starter Thread starter J_Reid
  • Start date Start date
J

J_Reid

Guest
I am getting a text string, which is a dimension, from a textbox and I need to break it into four parts. The first part will be feet, the next part will be inches the next part will be the numerator of the fraction and the last part will be the denominator of the fraction. I am using a regular expression to extract the four part into groups. The input string will look similar to this: 11'22 33/44". My regular expression works perfectly as long as there is only one character and it is anything other than a 0-9 between 11 and 22. My problem is that there may be a ' or '- or 'space-space or maybe some other combination of characters. I am hoping someone can show me how to skip a combination of more than one character. The code below is what I am using that works with only one character.


private void button1_Click(object sender, EventArgs e)
{
Regex regex = new Regex (@"(?<group1>\d+)[^0-9](?<group2>\d+)\s(?<group3>\d+)/(?<group4>\d+)");
Match match = regex.Match (textBox1.Text);
txtFeet.Text = ( match.Groups[1].Value );
txtInch.Text = ( match.Groups[2].Value );
txtNumerator.Text = ( match.Groups[3].Value );
txtDenominator.Text = ( match.Groups[4].Value );
}


Any help would be appreciated. I have tried everything that I have been able to find but apparently not in the right combination. Thank in advance.


JR

Continue reading...
 

Similar threads

E
Replies
0
Views
90
etl2016
E
L
Replies
0
Views
104
Lersubem
L
L
Replies
0
Views
71
Lincoln_MA
L
W
Replies
0
Views
61
want 2 Learn
W
Back
Top