Formula to extract numbers from text

I have text strings in the form

0' - Start of straight line, Road R-6 RD 0'
397' - Road R-5 RD 0', Start of straight line
9234' - Road R-29 RD 6247', End of road
6141' - Road R-1 RD 9233', Road R-29 RD 6239', End of road
739' - Road R-149 RD 0'
2534' - End of road, Road R-40 RD 2267'
0' - Start of straight line, Road R-1 RD 0', Road R-20 RD 0'


I need to extract the R- numbers and the RD values as shown in the attached file. Excel formula preferred but VBA is also acceptable.
Extract-number-and-values.xlsx
LVL 43
Saqib Husain, SyedEngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

scsymeCommented:
As a start you can put the following in B2 of your example and copy down:
=MID(A2,FIND("R-",A2)+2,FIND(" ",A2,FIND("R-",A2))-FIND("R-",A2)-2)

Open in new window


and the following into C2 of your example and copy down
=MID(A2,FIND("RD ",A2)+3,FIND("'",A2,FIND("RD ",A2))-FIND("RD ",A2)-3)

Open in new window


Columns D and E represent a second pair of R- and RD in the same data. Will they always occur in pairs? Is there a limit to the number of pairs per cell in column A?
Saqib Husain, SyedEngineerAuthor Commented:
Thanks for the formulas. Yes they will always be in pairs. I have two at the moment and I think that the maximum could be 4.
ProfessorJimJamMicrosoft Excel ExpertCommented:
Hi Saqib,

please find attached solution with UDF regular expression.
EE.xlsm
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

FloraCommented:
I am just curious how this can be done using formula instead of UDF
ProfessorJimJamMicrosoft Excel ExpertCommented:
Flora,

It is possible with formula, but the formula would be too lengthy, so if UDF does the job, why waste time with formula?

if you want this by formula, i suggest you open a new question.
scsymeCommented:
ProfJimJam is correct in that trying to do this in one long formula for the fourth instance (for example) would be too lengthy.
If you're happy to put up with some additional columns then this can be simplified somewhat as seen in the attached.

Hope that helps.
Extract-number-and-values--ss-.xlsx
Saqib Husain, SyedEngineerAuthor Commented:
I did it myself at home and came up with this formula to be entered in b2 and copied down and across.

=IFERROR(REPLACE(REPLACE($A10,FIND(IF(MOD(COLUMN(),2),"'"," "),$A10,FIND("##",SUBSTITUTE($A10,IF(MOD(COLUMN(),2),"RD ","R-"),"##",(COLUMN()-COLUMN($B10)+2)/2))),9999,""),1,FIND("##",SUBSTITUTE($A10,IF(MOD(COLUMN(),2),"RD ","R-"),"##",(COLUMN()-COLUMN($B10)+2)/2))+1,""),"")

It is big but not huge.
The regex needs a library to be loaded.

I shall keep this open a bit for someone to improve on this formula (Barry????). If not then then ProfessorJimJam's solution shall be an assist.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
scsymeCommented:
That's a pretty nifty solution. Nothing to add :-)
Saqib Husain, SyedEngineerAuthor Commented:
Found a preferred solution.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.