Search code examples
regexopenoffice.orgopenoffice-writer

Changing pairs of quotations marks to left and right quotation marks


tl;dr: Want to replace regular quotes ("...") with smart quotes (“...”), within OpenOffice's "Find/Replace" tool that has Regular Expressions turned on.

I figure the best way would be to find 2 instances of " with any length of any characters and white space between them, and replace either the first with a , or the second with a . Then, I could replace all " with the complementary quotation mark.

...it might be easier (for me—on my brain) if it's two separate regular expressions, even though I know some wizard could make it in one.


Okay, you can skip the rest now if you want, the mystical ‘cerfs sarcelle’ has pranced beyond your view, leaving a wall of text the sole subject...


Basic stuff, I know, but I can't get it quite right.

When looking in to regular expressions, I saw there were dozens of languages they were done in. None of which I can recognize. And couldn't find which one OO uses as its native, so I couldn't even use the generator I found to help. :\

I'm editing what's turning in to a novel, and some archaic typography is needed. Unlike double-spaces after periods, and using an em-dash for interrupted speech, this is a littler trickier to find and replace.

Any help would be much appreciated.

And if someone would be so kind as to break down each and every step of said regular expression, and which would logically be written first... Hell, I'd put you in the dedications (if I was writing it. Sadly, I am not.)

...and yes, a novel, edited in a free word processor... this will be self-published by the author, and I am doing it pro bono because they're my friend, how did you know? And? Why yes, I am unemployed! You are truly the magnificent seer of our times, o viewer of sadly obvious things! :P

Thanks!


Solution

  • Your idea of replacing pairs of quotation marks will work fine as long as there are no nested quotations (that is quotations within quotations) and no stray quotation marks which throw off the pairing.

    Now for the (extended) regular expressions.

    The expression you want to replace is: "(.*)". This searches for a pair of quotation marks with anything in between. The dot matches any one character and the star means zero or more repetitions of whatever precedes it (in this case dot). The parentheses are for catching whatever is matched in between, so we can refer to it as $1 in the replacement pattern, so we can copy it in the replacement, which should be “$1”.

    I used https://wiki.openoffice.org/wiki/Documentation/How_Tos/Regular_Expressions_in_Writer to determine the specific syntax OpenOffice uses for regular expressions, but it seems mostly pretty standard.