Regex expression

Hi There, how to write a regex expression to identify string match:
for ex: in my entire workbook it should highlight the summary column,  if it contains any string length greater than 6 digits or 8 digit. for ex: if summary column has 6 digit number it should highlight that row, if it has only 8 digit even then it should be highlighted, if it has both 6 and 8 digit it should get highlighted:

attached is the sample
kausalya durgaleAsked:
Who is Participating?

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

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.

Bill PrewCommented:
There is no easy way in Excel to apply conditional formatting like you are describing without creating a VBA macro to do the checking of the cell content to see if it matches your pattern.  Would it be acceptable to create a VBA procedure that you could use to do this, or is adding VBA to your workbook not an option?

Bill PrewCommented:
To give you an idea of how that would work, I'm attaching a sample workbook with the highlighting done in conditional formatting.

The conditional formatting uses a formula, which in turn uses a user defined function to test a cell value against a regular expression.  The formula in the conditional formatting applied to all of column D was:

=TestRegex($D1, "\b(?:[0-9]{6}|[0-9]{8})\b")

Open in new window

And the user defined function is as follows:

Public Function TestRegex(strText As String, strPattern As String) As Boolean
    With CreateObject("Vbscript.Regexp")
        .Global = False
        .IgnoreCase = True
        .Pattern = strPattern
        TestRegex = .Test(strText)
    End With
End Function

Open in new window



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
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
Regular Expressions

From novice to tech pro — start learning today.