Regex Help...Extracting distances from a line of text.
I have the following line of text
3 Smith, Nathan I5 Elite 13-07.75 15-05.25
and would like to extract the last distance (15-05.25). Its ok if I get both however. This is the pattern that I'm using:
\d+\s*[.'-]\s*\d+[.']\s*\d+\s*[.*m chr(34)]*\s*[^-\d*]*\s*\d*[chr(34)]*\s[^\d]
Unfortunatley, it only pulls the first distance (13-07.75).
The pattern is designed to extract distances given in many different formats.
Thank you.
Adrian
Re: Regex Help...Extracting distances from a line of text.
So if this is essentially a CSV row (where, instead of commas, it is spaces), why not split on ' ', and grab the last item in the array?
Re: Regex Help...Extracting distances from a line of text.
try this:
Code:
Dim rx As New regex("\d{2}\-\d{2}\.\d{2}$")
Re: Regex Help...Extracting distances from a line of text.
Quote:
Originally Posted by
adrian1906
I have the following line of text
3 Smith, Nathan I5 Elite 13-07.75 15-05.25
and would like to extract the last distance (15-05.25). Its ok if I get both however. This is the pattern that I'm using:
\d+\s*[.'-]\s*\d+[.']\s*\d+\s*[.*m chr(34)]*\s*[^-\d*]*\s*\d*[chr(34)]*\s[^\d]
Unfortunatley, it only pulls the first distance (13-07.75).
The pattern is designed to extract distances given in many different formats.
Thank you.
Adrian
.paul.'s solution will work if that's the format of the number you're using. If you want to match both then remove the $. You say that the distance can come in many different formats though so we'd need to know what formats you're expecting to give you a comprehensive answer.
I'm curious as to your regex though. You say it matches 13-07.75? From a cursory glance I can't see how that's possible since you're looking for chr(34) and there's no occurrence of that in the string you've supplied.
Re: Regex Help...Extracting distances from a line of text.
I'm seen distance represented quite a few ways in the document that I am parsing. Some examples include:
2'0.5" 10'5.2" 10- 00.00 11-03.00 1.54m 20 - 6.6
Re: Regex Help...Extracting distances from a line of text.
"\d{2}\-\d{2}\.\d{2}" worked but I had to remove the '$" at the end. I will try to incorporate this in a more general pattern to pull down all distances that satisfy a pre-determined format.
Re: Regex Help...Extracting distances from a line of text.
I put the chr(34) inside square brackets.
Some formats include:
2'0.5"
10'5.2"
10- 10.25
11- 03.00 (ie, strange spacing)
1.54m
20 - 6.6
20ft6.6in
20feet 6inches
20f6in