Little regex to convert single-line print statements in Python 2 to print() in Python 3:

s/print\s([^(\s].*)/print(\1)/g

Match pattern:

  • print: match string literally
  • \s: match a white space character
  • (: start capture group
    • [^(\s]: match a single character that is not ( or a white space
    • .* : match any character between zero and unlimited times
  • ): end capture group

Substitution expression takes the first capture group (i.e. everything inside the print statement) and outputs it in-between the parentheses of print().