7

I have a large text document with inconsistent quotation marks, i.e.

...Dolore magna aliquam “lorem ipsum” dolor sit amet, 'consectetuer adipiscing" elit, volutpat. Ut "wisi" enim...

and I want to convert every existing style of quotation only to one style, Guillemet style (» and «), so that example sentence should be like

...Dolore magna aliquam »lorem ipsum« dolor sit amet, »consectetuer adipiscing« elit, volutpat. Ut »wisi« enim...

Is that that possible only with find/replace with wildcards? The closest regex I got is

[“'"](?=[a-zA-Z\,\.\s])([a-zA-Z\,\.\s]*)[”'"]

but it is not working.

Thanks in advance!

  • Are there any quotes within quotes, and should these be treated differently? – thursdaysgeek Mar 31 '14 at 20:48
  • There are, but in that case even the nested quotes stay in » « style. – hihowareyou Mar 31 '14 at 21:05
3

Use the preceding/following space to determine which "side" of the word the quote you want is on.

\s in regex matches a whitespace character (ie a space, or tab, etc.).

So, first search for \s[“'"] and replace with <space>», then search for [”'"]\s and replace with «<space> (replace <space> with an actual space character :) ).

  • Simple and yet efficient, thanks! :) Although, MS Word doesn't seem to accept \s as a whitespace character (use wildcard is checked), but I'll go take a look on "Word for dummies" first :) But... is there a way to use regex in Word except through a find/replace screen (and VB macro, since I can't write in VB - I'm a novice in python and C#)? – hihowareyou Mar 31 '14 at 21:16
  • And another newbie question; what about when a quotation mark is right before comma or a stop sign, i.e. "sample text", "second text".? – hihowareyou Mar 31 '14 at 21:44
  • Just group stops with the space, ie: [”'"][\s,.]. If you can read and write C# you can read and write VB(A). ;) – Ƭᴇcʜιᴇ007 Apr 1 '14 at 20:16
  • For future readers, the equivalent to \s that I use in wildcards is [ ^s^t]: literal space, nonbreaking space (^s), and tab (^t). – cxw Apr 20 '18 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.