Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2007

Tip: Looking for answers? Try searching our database.

question about regular expressions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
muyBN - 05 Jun 2007 21:55 GMT
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...

Signature

Bryan

Helmut Weber - 05 Jun 2007 23:57 GMT
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
[quoted text clipped - 3 lines]
>
>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

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Jay Freedman - 06 Jun 2007 00:55 GMT
>Are regular expressions only for searching or can they also be used for
>matching? I read a 4GuysFromRolla article that only mentioned searching. I
[quoted text clipped - 5 lines]
>
>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        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.