wildcard code for paragraph

O

Old Lars

I'm porting a Word VBA macro from Windows to Mac. At one point it does
a wildcard search and replace of "^13[^13]@" to "^p"; in other words,
it finds two or more paragraph marks and replaces them with one. Works
fine on Windows. On Mac, it complains that ^13 is not a valid
character in a wildcard search. What character should I be using? ^p
does not work, but of course it doesn't work on Windows either.
TIA--
 
E

Elliott Roper

Old Lars said:
I'm porting a Word VBA macro from Windows to Mac. At one point it does
a wildcard search and replace of "^13[^13]@" to "^p"; in other words,
it finds two or more paragraph marks and replaces them with one. Works
fine on Windows. On Mac, it complains that ^13 is not a valid
character in a wildcard search. What character should I be using? ^p
does not work, but of course it doesn't work on Windows either.
TIA--
Interesting question.
So far, only a crap answer.

Loop the macro replacing ^p^p with ^p till it makes no replacements (no
wildcards).

I wonder why Word excludes paragraph marks from wild cards?
One answer could be that it might surprise the user when there are two
para marks in different styles. Woosy really.

It is a fairly common operation to get rid of excess paragraph marks,
especially from text harvested from dodgy sources, like web pages and
OCR muck.

Maybe we should petition the MacBU for (gasp) a new feature?
 
O

Old Lars

Elliott Roper said:
Old Lars said:
I'm porting a Word VBA macro from Windows to Mac. At one point it does
a wildcard search and replace of "^13[^13]@" to "^p"; in other words,
it finds two or more paragraph marks and replaces them with one. Works
fine on Windows. On Mac, it complains that ^13 is not a valid
character in a wildcard search. What character should I be using? ^p
does not work, but of course it doesn't work on Windows either.
TIA--
Interesting question.
So far, only a crap answer.

Loop the macro replacing ^p^p with ^p till it makes no replacements (no
wildcards).

I wonder why Word excludes paragraph marks from wild cards?
One answer could be that it might surprise the user when there are two
para marks in different styles. Woosy really.

It is a fairly common operation to get rid of excess paragraph marks,
especially from text harvested from dodgy sources, like web pages and
OCR muck.

Maybe we should petition the MacBU for (gasp) a new feature?

Thanks, Elliott. I found a way, by accident and pig-headedness. The
following works in Windows and Mac:

Find:
[\^013][\^013]@([!\^013])

Replace:
^p\1

I had to escape the character and use the 3-digit form and put it in
class markers (brackets). This doesn't handle multiple hard returns at
the very end of the file, but that doesn't affect what I'm doing.

(BTW, my logic was faulty in the original that "worked" on
Windows...it only picked up pairs of hard returns. I always forget
that wildcard matches in VBA are not greedy, unlike Perl [which I'm
more familiar with], where they are greedy.)

---L
 
O

Old Lars

Elliott Roper said:
Old Lars said:
I'm porting a Word VBA macro from Windows to Mac. At one point it does
a wildcard search and replace of "^13[^13]@" to "^p"; in other words,
it finds two or more paragraph marks and replaces them with one. Works
fine on Windows. On Mac, it complains that ^13 is not a valid
character in a wildcard search. What character should I be using? ^p
does not work, but of course it doesn't work on Windows either.
TIA--
Interesting question.
So far, only a crap answer.

Loop the macro replacing ^p^p with ^p till it makes no replacements (no
wildcards).

I wonder why Word excludes paragraph marks from wild cards?
One answer could be that it might surprise the user when there are two
para marks in different styles. Woosy really.

It is a fairly common operation to get rid of excess paragraph marks,
especially from text harvested from dodgy sources, like web pages and
OCR muck.

Maybe we should petition the MacBU for (gasp) a new feature?

Thanks, Elliott. I found a way, by accident and pig-headedness. The
following works in Windows and Mac:

Find:
[\^013][\^013]@([!\^013])

Replace:
^p\1

I had to escape the character and use the 3-digit form and put it in
class markers (brackets). This doesn't handle multiple hard returns at
the very end of the file, but that doesn't affect what I'm doing.

(BTW, my logic was faulty in the original that "worked" on
Windows...it only picked up pairs of hard returns. I always forget
that wildcard matches in VBA are not greedy, unlike Perl [which I'm
more familiar with], where they are greedy.)

---L
 
E

Elliott Roper

Old Lars said:
Elliott Roper said:
Old Lars said:
I'm porting a Word VBA macro from Windows to Mac. At one point it does
a wildcard search and replace of "^13[^13]@" to "^p"; in other words,
it finds two or more paragraph marks and replaces them with one. Works
fine on Windows. On Mac, it complains that ^13 is not a valid
character in a wildcard search. What character should I be using? ^p
does not work, but of course it doesn't work on Windows either.
TIA--
Interesting question.
So far, only a crap answer.

Loop the macro replacing ^p^p with ^p till it makes no replacements (no
wildcards).

I wonder why Word excludes paragraph marks from wild cards?
One answer could be that it might surprise the user when there are two
para marks in different styles. Woosy really.

It is a fairly common operation to get rid of excess paragraph marks,
especially from text harvested from dodgy sources, like web pages and
OCR muck.

Maybe we should petition the MacBU for (gasp) a new feature?

Thanks, Elliott. I found a way, by accident and pig-headedness. The
following works in Windows and Mac:

Find:
[\^013][\^013]@([!\^013])

Replace:
^p\1

I couldn't get that to work in find and replace. Is that syntax \^013
only good for macros?
 
O

Old Lars

Elliott Roper said:
I couldn't get that to work in find and replace. Is that syntax \^013
only good for macros?

No, I tested it via find and replace, then tried it in my macro.
Worked both ways, on both platforms. This is Word 2000 on Mac OS 9.1,
and Word 2000 on Windows 2000.
 
E

Elliott Roper

Old Lars said:
No, I tested it via find and replace, then tried it in my macro.
Worked both ways, on both platforms. This is Word 2000 on Mac OS 9.1,
and Word 2000 on Windows 2000.

Thanks. Anyone else with v.X willing to try it?
 
J

John McGhie [MVP - Word]

Hi Elliot/Lars:

Yep. Works in 2004. Remember to turn "Use wildcards on" :)

Lars: You know there is a VBA constant for "paragraph"? I would use that
if you can, particularly working cross-platform, where you have to deal with
PC paragraphs (0D0A) Mac Paragraphs (0D) and Unix Line enders (I can't
remember what they are...)

cheers


from said:
Thanks. Anyone else with v.X willing to try it?

--

Please respond only to the newsgroup to preserve the thread.

John McGhie, Consultant Technical Writer,
McGhie Information Engineering Pty Ltd
Sydney, Australia. GMT + 10 Hrs
+61 4 1209 1410, mailto:[email protected]
 

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