|
-
May 10th, 2013, 07:52 AM
#1
Thread Starter
Addicted Member
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
-
May 10th, 2013, 07:57 AM
#2
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?
-
May 10th, 2013, 08:01 AM
#3
Re: Regex Help...Extracting distances from a line of text.
try this:
Code:
Dim rx As New regex("\d{2}\-\d{2}\.\d{2}$")
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 10th, 2013, 09:02 AM
#4
Re: Regex Help...Extracting distances from a line of text.
 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.
This pattern in common to all great programmers I know: they're not experts in something as much as experts in becoming experts in something.
The best programming advice I ever got was to spend my entire career becoming educable. And I suggest you do the same.
-
May 10th, 2013, 12:58 PM
#5
Thread Starter
Addicted Member
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
-
May 10th, 2013, 01:02 PM
#6
Thread Starter
Addicted Member
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.
Last edited by adrian1906; May 10th, 2013 at 01:06 PM.
-
May 10th, 2013, 01:06 PM
#7
Thread Starter
Addicted Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|