regular expressions

L

Laura

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
 
D

Doug Robbins - Word MVP

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

--
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
 
L

Laura

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


Doug Robbins - Word MVP said:
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

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

Laura said:
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
 
D

Doug Robbins - Word MVP

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.

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

Laura said:
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


Doug Robbins - Word MVP said:
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

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

Laura said:
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
 
T

Tony Jollans

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


Doug Robbins - Word MVP said:
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.

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

Laura said:
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


Doug Robbins - Word MVP said:
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

--
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
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
 
D

Devacann

Laura said:
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


to remove numbers from document... all numbers, you must use:

with selection.find
.text = "[0-9]@"
.replacement.text = ""
.wrap:=wdfindcontinue
.matchwildcards = true
end with
selection.find.execute replace:=wdreplaceall
 

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