擅长:python、mysql、java
<p>您可以通过re模块和一个替换函数来实现这一点。你知道吗</p>
<pre><code>import re
# make the re pattern object
# it looks for the following pattern: 2 digits / 2 digits / 4 digits
date_pattern = re.compile(r'\d{2}/\d{2}/\d{4}')
# make the replacement function to be called to replace matches
# takes the match object, splits the date up and swaps the first two elements
def swap_date_arrangement(date_string):
return_string = date_string.group(0).split('/')
return_string[0], return_string[1] = return_string[1], return_string[0]
return '/'.join(return_string)
# test the solution...
input_string = "I graduated on 09/08/2016 and joined PHD on 01/07/2017 then since 25/10/2011 I work on..."
# assign the new string
replaced_string = re.sub(date_pattern, swap_date_arrangement, input_string)
print replaced_string
</code></pre>