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 / November 2006

Tip: Looking for answers? Try searching our database.

regular expressions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Laura - 02 Nov 2006 11:26 GMT
hi!
the desired result of a procedure that i'm doing is to find the words that
begin with a digit and eliminate this digit (1CD must convert to CD, and P2P
must remain equal)
so, first, i would like somebody answer me a question: (it's an easy
question )
is it possible to use wildcards with the  'replace' function or i'm obliged
to to a find-replace function:

Selection.Find.ClearFormatting
       With Selection.Find
           .Text = "mytext"
           .Replacement.Text = "myreplacetext"
           .Forward = True
           .Wrap = wdFindContinue
           .Format = True
           .MatchCase = True
           .MatchWholeWord = False
           .MatchWildcards = true
           .MatchSoundsLike = False
           .MatchAllWordForms = False
       End With
Selection.Find.Execute Replace:=wdReplaceAll

and, at last, to ask how can i create the regular expression that removes
all the digits in a text, I've try with [0-9]* and with [0-9]{1,} but it
doesn´t works fine.
[0-9]* ->find individual digits
[0-9]{1,} -> gives me an error

thank you
Doug Robbins - Word MVP - 02 Nov 2006 13:33 GMT
You can simply use Edit Replace with the Match Wildcards box checked and
with

[0-9]{1,}([A-z]{1,})

in the Find what control, and

\1

in the Replace with control.  Note that each of the above Find and Replace
strings start with a space

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> hi!
> the desired result of a procedure that i'm doing is to find the words that
[quoted text clipped - 29 lines]
>
> thank you
Laura - 02 Nov 2006 15:36 GMT
Hi Doug!
thank you very much for answer the post, but it doesn't work at my computer.
I get the error number 5560. I've look up for this error in internet, and
there is people thant thinks thant the error can be caused for the regional
configuration ( my languaje isn't english as can apreciate in my writing).
Other people thinks that is due for use :  Selection.Find.Execute
Replace:=wdReplaceAll with Wildcards, i don't know,
but i get what i was looking for:

Selection.Find.ClearFormatting
   Selection.Find.Replacement.ClearFormatting
   With Selection.Find
       .Text = "[0-9]{1,}([A-z]{1,})"
       .Replacement.Text = "\1"
       .Forward = True
       .Wrap = wdFindContinue
       .Format = False
       .MatchCase = False
       .MatchWholeWord = False
       .MatchAllWordForms = False
       .MatchSoundsLike = False
       .MatchWildcards = True
   End With
   Selection.Find.Execute Replace:=wdReplaceAll

> You can simply use Edit Replace with the Match Wildcards box checked and
> with
[quoted text clipped - 41 lines]
> >
> > thank you
Doug Robbins - Word MVP - 02 Nov 2006 19:46 GMT
I was not suggesting that you use a macro, just the Replace item on the Edit
menu.  Depending on the thousands separator and the decimal character you
may need to replace the commas in the search string with semi-colons or
something else.

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Hi Doug!
> thank you very much for answer the post, but it doesn't work at my
[quoted text clipped - 73 lines]
>> >
>> > thank you
Tony Jollans - 02 Nov 2006 20:31 GMT
If your regional options use comma as decimal point, they will then use
semicolon as separator so try changing the string to  [0-9]{1;}([A-z]{1;})

--
Enjoy,
Tony

> I was not suggesting that you use a macro, just the Replace item on the Edit
> menu.  Depending on the thousands separator and the decimal character you
[quoted text clipped - 94 lines]
> >> >
> >> > thank you

Rate this thread:






 
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.