Regex Pattern for Numerical Data beginning with Zero Only

NimishK

Well-known Member
Joined
Sep 4, 2015
Messages
688
Hello

Anyone has any idea How can I Match Numerical/Digit beginning with Zero Only (single digit /First digit) . I've come across some links
using the same with REGEX but did not understand as it has gone over my head
in below coding have few numerical data and from below string How to get the following Number only 000106714972555

VBA Code:
Dim stringOne As String
Dim regexOne As Object

Set regexOne = New RegExp
regexOne.Pattern ="\b\d{10, }\b"

StringOne = "90200025272451     PYMT OF BILL NO 1634      000106714972555      INR   17,250.00"

Set theMatches = regexOne.Execute(stringOne)
Debug.Print regexOne

It Prints only 90200025272451

Your input and correction will be helpful

Thanks
NimishK
 
Last edited:
Peter_SSs Sir

Thank you so much for your valuable input.

VBA Code:
Dim myNum As String
regexOne.Pattern = "(^|\D)(0\d{8,})"

stringOne = "90200025272451     PYMT OF BILL NO 1634      000106714972555      INR   17,250.00"
myNum = "Not found"
If regexOne.test(stringOne) Then myNum = regexOne.Execute(stringOne)(0).submatches(1)

Sir Is it necessary/or a compulsion to give IF and THEN for a Regex Match Found True
Can we not directly myNum = regexOne.Execute(stringOne)(0).submatches(1)

Thanks
NimishK
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Sir Is it necessary/or a compulsion to give IF and THEN for a Regex Match Found True
Can we not directly myNum = regexOne.Execute(stringOne)(0).submatches(1)
I don't know what your actual data is like as you have only given one example string. If you do it without the IF test and no match is found in the string the code will error.
It is a safety measure to stop any such error.
 
Upvote 0
Peter_SSs Sir

I don't know what your actual data is like as you have only given one example string. If you do it without the IF test and no match is found in the string the code will error.
It is a safety measure to stop any such error.
Sir Actually no actual data as you commented. I think Better to go with IF THEN.... in order to avoid error.
This thread was to understand the REGEX ... Execute Matches and Submatches etc

Also this reminds that there are VBA Excel Syntaxes that one cannot Execute without IF THEN generating error

Thank you sir indeed you have explained so nicely on each and every point asked to you. Many things have become clearer

NimishK
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top