On 30/10/2007 19:01, Mark Hull-Richter wrote:
This could just be my own misunderstanding of something, or a feature that
doesn't exist.

I frequently use the writer's search to locate or replace items in my
documents, but I recently tried to use a wildcard search and replace, and it
failed miserably.

I want to find all instances of the end of a sentence that is followed by a
single space and replace the single space with a double space.

The search term, with "regular expressions" selected, is <[.!?]["']* [^ ]>
(ignore the <> - they are my separators for this because it contains most of
the usual quoting characters; a period, exclamation mark or question mark,
optionally followed by one or more quote marks, followed by a space,
followed by anything that is not a space.  This works just fine.

What is the replacement expression?

I have looked at the help sections, but there is no information on
replacement expressions.

As far as I can tell, it is not available in Word, either.  It is, however,
a fairly simple expression in vi, sed and all related Linux/Unix text editor
programs (I'm guessing emacs can also do this, but I've never used it).  The
vi command is :g/\([.!?]["']* \)\([^ ]\)/s//\1 \2/g (globally search for the
expression, grouping the front and back separately, replace with part one,
space, part two, globally on each line as well).

Is this possible in OOo at all?

(And, no, to convert to vi, do this and convert back is not practical - they
are already conversions from text files, and this problem wasn't present in
them.)

Thanks.

mhr

I believe you have found the same shortcoming in OO's handling of REs that I found a while ago. The use of parentheses to group a sub-pattern and the subsequent use of \1, \2 etc. to refer to the first, second etc. group *only* works within the "find" pattern; it does not transfer to the "replacement" pattern. To quote the Help text under "Regular Expressions":

--- start quote ---
(): Defines the characters inside the parentheses as a reference. You can then refer to the first reference in the current expression with "\1", to the second reference with "\2", and so on. For example, if your text contains the number 13487889 and you search using the regular expression (8)7\1\1, "8788" is found. You can also use () to group terms, for example, "a(bc)?d" finds "ad" or "abcd".
--- end quote ---

<thought>
However, as a kludge, given that your list of "end of sentence" characters is only 3 characters: full stop, question mark and exclamation mark, and your list of quote characters has only 2 entries: single and double quote, you could do it with 6 patterns - each of the 3 sentence-enders with each of the 2 quote characters (not sure why you'd need to allow for multiple quote marks). That's a pain of course but *I think* you could write a macro to do it.

Oh, what about the "directional" quotes ` and ยด (perhaps referred to as grave and acute accent respectively) that sometimes appear in HTML documents? Of course, only the second of those *should* appear at the end of something. And there are directional double quotes too but they could be handled by judiciously configuring Tools>AutoCorrect>Custom Quotes. More combinations but the same principle
</thought>

But of course that's wrong. You do need multiple quotes to handle cited quotations or quoted cited quotations or ... so the kludge won't catch everything.

Ahhh. What about just changing all occurrences of multiple spaces to a single space. This does *not* affect fully justified text although it may spoil specially formatted text so ... In fact, Tools>AutoCorrect>Options can be configured to "Ignore double spaces".

Hope this is food for thought.

--
Harold Fuchs
London, England
Please reply *only* to users@openoffice.org

Reply via email to