\ 1 \ 2 \ 3 in the regular problems

import re

s = "Today is 3/2/2017 。Pycon starts 5/25/2017"

new_s = re.sub("(\d+)/(\d+)/(\d+)",r"\3-\1-\2",s)
print(new_s)

Output

Today is 2017-3-2 。Pycon starts 2017-5-25

First, \ 1 \ 2 \ 3 fitted to the front of several bracketed used, such as where \ 3 is to match the third set of parentheses, \ 2 of the second group, \ 1 is the first set.

Guess you like

Origin www.cnblogs.com/c-x-a/p/11002041.html