Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regexp and Decimals 1

Status
Not open for further replies.

vladk

Programmer
May 1, 2001
991
US
Hi, how with Regular Rexpressions extract numbers from a string? Including decimals. For example:

"Blallaal $3.4566 UI<><>" should be just 3.4566
"345 hjkhehj###" shuld be 345

Thanks

vladk
 
How about this?
[tt] .pattern="\d+(\.\d+){0,1}"
[/tt]
 
tsuji,

I tried this code with your pattern, and it did not do the job:

With objRegExp
.Global = True
.MultiLine = True
.IgnoreCase = True
.Pattern = "d+(\.\d+){0,1}"
strReturn = .Replace(pstrText, vbNullString)
End With

vladk
 
There is a slash leading...
> .Pattern = "d+(\.\d+){0,1}"
[tt] .Pattern = "[red]\[/red]d+(\.\d+){0,1}"[/tt]

 
tsuji,

Hi, thank you for the responce. I actually need to get the numbers, I need to see them.

vladk
 
>I actually need to get the numbers, I need to see them
>strReturn = .Replace(pstrText, vbNullString)

This is about it. Try it?

[tt]if .test(pstrText) then
strReturn = .execute(pstrText)(0)
else
strReturn = ""
end [/tt]
 
Mine >end should be read[tt] end if[/tt].
 
tsuji,

Works great!!!

Thank you!!!

vladk


 
>Works great!!!

Works sufficiently, I suspect you mean.

For example, many European countries use . as a date seperator, e.g.

Today is 28.06.2006

which the regexp given above would identify as a decimal 28.06
 
Also, if the number appears as ".1234" The leading "." lost significance as part of a number and treated semantically as the period of some statment not decimal separator.

I guess there's always thing to improve... But after seeing a working instance, op could build upon it and would soon be better than anybody else on a particular configuration of interest to his work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top