How to Search a Numeric value inside a String ?

Hello Automation lovers, during these sweltering summers it is really arduous to share
something with the community. From a long time, I was thinking to share some logic for 
searching numbers in a Text.
Search Me UFT
By the grace of GOD, today is lucky Day 🙂

Scenario: – How we can search a Numeric Value inside a given Text/String/File?


Note: – Please refer the link on RegularExpression Object for more understanding of the

'Function Name:- fn_SearchNumeric
'Function Description:- Used to find the Numeric values inside a string
'Input Parameters:- Sting
'Output Parameters:- Final Search Message
'Created By :-
'Date:- 19th June,2014
msgbox fn_SearchNumeric("Please search 89766 Numeric values")

Function fn_SearchNumeric(strSearchString)
Set objRegExp = CreateObject("VBScript.RegExp")
objRegExp.Global = True
'Regular Expression to search Numeric values
objRegExp.Pattern = "d"
Set objMatches = objRegExp.Execute(strSearchString)
'Incase match is found
If objMatches.Count > 0 Then
strMessage = "The given string '"&strSearchString&"'
has the following numeric values:-" & vbCrlf
iNumeric = ""
For Each sMatch in objMatches
iNumeric = iNumeric & sMatch.Value
fn_SearchNumeric = strMessage & iNumeric
fn_SearchNumeric = "Sorry No match found!!Please correct
the String to search"
End If
End Function

Leave a Reply

Your email address will not be published. Required fields are marked *