question about regular expressions

M

muyBN

Are regular expressions only for searching or can they also be used for
matching? I read a 4GuysFromRolla article that only mentioned searching. I
was wondering if it's possible to do something like the following:

if Selection=[a-z/A-Z/0-9] then...

....or better yet:

If instr(Selection,[a-z/A-Z/0-9])=1 then...
 
H

Helmut Weber

Hi Bryan,
Are regular expressions only for searching or can they also be used for
matching? I read a 4GuysFromRolla article that only mentioned searching. I
was wondering if it's possible to do something like the following:

if Selection=[a-z/A-Z/0-9] then...

If instr(Selection,[a-z/A-Z/0-9])=1 then...

this is about the same.
You can search the selection using a wildcard search.

Sub Test334()
Dim r As Range
Set r = Selection.Range
With r.Find
.Text = "[a-z][A-Z][0-9]"
.MatchWildcards = True
If .Execute Then
MsgBox "yes"
End If
End With
End Sub

When searching the selection,
previously parameters (options) are remembered.
Not so, IMHO, if you define a new range.

Though, there are a lot of peculiarities...

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
J

Jay Freedman

Are regular expressions only for searching or can they also be used for
matching? I read a 4GuysFromRolla article that only mentioned searching. I
was wondering if it's possible to do something like the following:

if Selection=[a-z/A-Z/0-9] then...

...or better yet:

If instr(Selection,[a-z/A-Z/0-9])=1 then...

Check the VBA help topic about the Like operator. It's similar to
regular expressions, although (typical Microsoft) not quite the same.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top