I need to parse out the first number to the immediate left of the
first letter in each of the words. For example, the output would be
2,3,3,3,3

2GreysIceStorm 1093Pnj'sPromenade 31.053Pnj'sPromenade
3Pnj'sPromenade 3Pnj'sPromenade

In this line of text:

4Bob'sHammer 1008Leta'sCharlotte 31.166MaryvilleShep
5Keyless 2GreysIceStorm

The output would be 4,8,6,5,2

Is this possible with vbscript. Is there a way to make a script look
for the first number to the immediate left of any letter?

Re: How would you parse the nubers out of this text? by Han

Han
Mon Dec 01 21:12:04 CST 2003

Try,

a=MY_TEXT

set re=new regexp: re.global=true
re.pattern="(\d)[a-zA-Z]"

for each v in re.execute(a)
msgbox v.submatches(0)
next

--
Pohwan Han, Microsoft MVP, ASP/ASP.Net, Korea
Have a nice day.

"csormond" <csutton@tampabay.rr.com> wrote in message
news:8c5991c.0312011802.589d50e7@posting.google.com...
> I need to parse out the first number to the immediate left of the
> first letter in each of the words. For example, the output would be
> 2,3,3,3,3
>
> 2GreysIceStorm 1093Pnj'sPromenade 31.053Pnj'sPromenade
> 3Pnj'sPromenade 3Pnj'sPromenade
>
> In this line of text:
>
> 4Bob'sHammer 1008Leta'sCharlotte 31.166MaryvilleShep
> 5Keyless 2GreysIceStorm
>
> The output would be 4,8,6,5,2
>
> Is this possible with vbscript. Is there a way to make a script look
> for the first number to the immediate left of any letter?



Re: How would you parse the nubers out of this text? by Torgeir

Torgeir
Mon Dec 01 21:26:56 CST 2003

Han wrote:

> Try,
>
> a=MY_TEXT
>
> set re=new regexp: re.global=true
> re.pattern="(\d)[a-zA-Z]"
>
> for each v in re.execute(a)
> msgbox v.submatches(0)
> next

Nice :-)

One small note here for the OP: "WSH" 5.5 or better needs to be installed to
make the "submatches" statement work...


--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter



Re: How would you parse the nubers out of this text? by csutton

csutton
Wed Dec 03 21:00:41 CST 2003

Thanks, that worked great. I am kind of new to VBScripting and have
a couple of questions about the code. What does the (\d) represent?
I am assuming it means the first integer to the left. Am I close?
and can you explain the "submatches(0)" statement? and Why (0)?

Thanks,
Chris




"Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message news:<3FCC0680.4B25C8B3@hydro.com>...
> Han wrote:
>
> > Try,
> >
> > a=MY_TEXT
> >
> > set re=new regexp: re.global=true
> > re.pattern="(\d)[a-zA-Z]"
> >
> > for each v in re.execute(a)
> > msgbox v.submatches(0)
> > next
>
> Nice :-)
>
> One small note here for the OP: "WSH" 5.5 or better needs to be installed to
> make the "submatches" statement work...

Re: How would you parse the nubers out of this text? by Michael

Michael
Wed Dec 03 22:14:18 CST 2003

> Thanks, that worked great. I am kind of new to VBScripting and have
> a couple of questions about the code. What does the (\d) represent?
> I am assuming it means the first integer to the left. Am I close?
> and can you explain the "submatches(0)" statement? and Why (0)?


Introduction to Regular Expressions
http://msdn.microsoft.com/library/en-us/script56/html/reconintroductiontoregularexpressions.asp

Regular Expression Syntax
http://msdn.microsoft.com/library/en-us/script56/html/jsgrpregexpsyntax.asp

Matches Collection
http://msdn.microsoft.com/library/en-us/script56/html/vscolMatches.asp

SubMatches Collection
http://msdn.microsoft.com/library/en-us/script56/html/vscolSubMatches.asp


WSH 5.6 documentation download
http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en


--
Michael Harris
Microsoft.MVP.Scripting