4

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!

Ben
  • 43
  • 2
  • wouldn't a simple ``" search work for open quotes and "`` work for most close instances (you might want "`` too) – Robert Longson Dec 21 '15 at 21:21
  • I still don't know what language OO uses (couldn't find it listed on their wiki article for regex https://wiki.openoffice.org/wiki/Documentation/How_Tos/Regular_Expressions_in_Writer for some reason), but maybe all languages would, but: – Ben Dec 21 '15 at 21:29
  • That might, yes _mostly_. For left quotes it would need to find space (as in the space bar press), a new line, a tab, etc. Which would work as long as a mistake hasn't been made and a space was put in mid-line. But I can fix that fairly easily, so yeah. But again, I don't know how to write that either. And while this may solve my problem, I'd appreciate someone writing up how to find the 2 occurrences with text between, and selecting the 2nd (or 1st) of those to be replaced. – Ben Dec 21 '15 at 21:29
  • *Update:* Using similar requests I've blindly toyed and gotten almost there with this: http://regexr.com/3cf3f Finding: `/(")(?:(?=(\\?))\2.)*?\1/g` ...has found things right, but replacing: `\“$&”\n\t` ...leaves the original (") characters, essentially making `"..."` in to `“"..."”` – Ben Dec 21 '15 at 21:40

1 Answers1

2

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.

hkBst
  • 2,818
  • 10
  • 29
  • (Sorry for the "it didn't work" comments, turns out I was wrong) That actually _does_ work in OpenOffice, it just didn't in **regexr** for some reason: http://regexr.com/3cf3l Thank you so much! – Ben Dec 21 '15 at 22:03
  • Probably because \1 is more usual to refer to a group, instead of $1 – hkBst Dec 21 '15 at 23:06
  • Make sure the matching is ungreedy, assuming no nested quotes. – qwr Aug 05 '23 at 02:04