Home > Software design >  How can I automatically replace double with single quotes, based on condition (regex)?
How can I automatically replace double with single quotes, based on condition (regex)?

Time:08-22

I have about 20.000 quotation marks in my project. I want to automatically replace them based on the content. For simplicity, let's consider that it's all double quotes.

If the characters inbetween quotes are all CAPS, then it should be a single quote and else, it should be double quotes.

I figured that the best way to do this would be using regular expressions, but I don't know how. I'm grateful for any help.

(Python in VSCode)

CodePudding user response:

Try

Find: "([A-Z .] )"

Replace: '$1'

CodePudding user response:

  1. Replace all quotes to double quotes..
  2. Use this regex to find and replace all quotes to single quotes /(["])[A-Z] (["])/

Read regex docs https://docs.python.org/3/library/re.html

  • Related