str = 'php|java|python|javascript|html'
print('php' in str)
import re
str = 'php|java|python|javascript|html'
result = re.findall('php',str)
print(result)
import re
str = 'php123java312python123javascript123html'
print(re.findall('\d', str))
import re
str = 'abc,afc,adc,arc'
print(re.findall('a[bf]c',str))
print(re.findall('a[^bf]c',str))
import re
str = 'pytho1python2pythonn0'
print(re.findall('python*',str))
print(re.findall('python+',str))
print(re.findall('python?',str))
str = 'PythonPythonPython'
print(re.findall('(Python){3}',str))
str = 'PythonPython'
print(re.findall('(Python){3}',str))
str = 'PythonPythonPythonPython'
print(re.findall('(Python){3}',str))
str = 'PythonPHPc++'
print(re.findall('php',str,re.I))
str = 'PythonPHPc++'
print(re.findall('php',str,re.S))
str = 'c++PythonPHPc++'
print(re.sub("c\+\+", 'Go', str))
print(re.sub("c\+\+", 'Go', str, 1))
str = 'c++PythonPHPc++'
def deal_str(value):
match = value.group()
return '!!' + match + '!!'
print(re.sub("c\+\+", deal_str, str))
本作品採用《CC 協議》,轉載必須註明作者和本文連結