I want to delete whatever text between certain "tags" (note that I need
to remove html css comments as well as PHP comments)
so I have the following code
Sub EliminarCSSComments()
Dim oRng As Range
Set oRng = ActiveDocument.Content
With oRng.Find
.ClearFormatting
.Text = "/#*#/"
.Forward = True
.Wrap = wdFindStop 'para cuando se llega al final del documento
.MatchWildcards = True
Do While .Execute
oRng.Select
MsgBox "encontro"
oRng.Delete
Loop
End With
this works quite well if I wanted to delete text between /# and #/
see for instance this example
if I have
/# this should be removed #/
/# this should /be re#moved #/
both lines will be deleted.
but in the other hand, when I want to delete the text between /* and */
(wich is actually what I need), the code won't work as expected
for instance, if I have
/* this should be removed */
/* this sho/uld be r*emoved */
the result is
uld be r*emoved */
note that I tryied with the following text to search
.Text = "/" + Chr(42) + "*" + Chr(42) + "/"
'.Text = "/* */"
'.Text = "/*/"
'.Text = "/\*?{1,}\*/"
'.Text = "/**/"
'.Text = "</*>*<*/>"
'.Text = "/\*?{1,}\*/"
the problem seems to be that i need to search for asterisks(*), which
are seen by Word as wildcards...
any hint?
sdos - jm
Tony Jollans - 18 Mar 2006 02:08 GMT
Hi Julian,
You are correct in your assumption about the asterisks. To find an actual
asterisk you must 'escape' it by preceding it with a backslash - so looking
for "/\*" (with wildcards) finds "/*" rather than "/anything"
--
Enjoy,
Tony
> I want to delete whatever text between certain "tags" (note that I need
> to remove html css comments as well as PHP comments)
[quoted text clipped - 56 lines]
>
> sdos - jm
Jay Freedman - 18 Mar 2006 02:32 GMT
Because an asterisk has a special meaning in search expressions, each
'real' asterisk must be preceded by a backslash. The search expression
should be
.Text = "/\*(*)\*/"
The first and third asterisks will match actual asterisk characters,
and the second asterisk will match everything between them. It doesn't
seem to me that the parentheses should be necessary if you aren't
using the \1 group in the replacement, but the search doesn't find
anything if they're omitted.
By the way, if you can do without the message box, you can speed up
you macro by rewriting it this way:
Sub EliminarCSSComments()
Dim oRng As Range
Set oRng = ActiveDocument.Content
With oRng.Find
.ClearFormatting
.Text = "/#*#/"
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
End Sub
--
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.
>I want to delete whatever text between certain "tags" (note that I need
>to remove html css comments as well as PHP comments)
[quoted text clipped - 56 lines]
>
>sdos - jm
julian_m - 18 Mar 2006 02:42 GMT
> Because an asterisk has a special meaning in search expressions, each
> 'real' asterisk must be preceded by a backslash. The search expression
> should be
>
> .Text = "/\*(*)\*/"
It works like a charm, even though I ask myself what means the
parentheses there...
I now understand how to search for special characters.
> By the way, if you can do without the message box, you can speed up
> you macro by rewriting it this way:
Right. I was using the message box just to know what was happening
with the code ; )
Thank you very much.
saludos - jm
Graham Mayor - 18 Mar 2006 07:52 GMT
http://www.gmayor.com/replace_using_wildcards.htm will help with wildcard
syntax.

Signature
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>> Because an asterisk has a special meaning in search expressions, each
>> 'real' asterisk must be preceded by a backslash. The search
[quoted text clipped - 15 lines]
>
> saludos - jm