Regex Match all characters between two strings

后端 未结 14 1021
星月不相逢
星月不相逢 2020-11-21 07:42

Example: \"This is just\\na simple sentence\".

I want to match every character between \"This is\" and \"sentence\". Line breaks should be ignored. I can\'t figure o

14条回答
  •  爱一瞬间的悲伤
    2020-11-21 08:07

    I landed here on my search for regex to convert this print syntax between print "string", in Python2 in old scripts with: print("string"), for Python3. Works well, otherwise use 2to3.py for additional conversions. Here is my solution for others:

    Try it out on Regexr.com (doesn't work in NP++ for some reason):

    find:     (?<=print)( ')(.*)(')
    replace: ('$2')
    

    for variables:

    (?<=print)( )(.*)(\n)
    ('$2')\n
    

    for label and variable:

    (?<=print)( ')(.*)(',)(.*)(\n)
    ('$2',$4)\n
    

    How to replace all print "string" in Python2 with print("string") for Python3?

提交回复
热议问题