面试题答案
一键面试import re
string = 'The quick brown fox jumps over the lazy dog. Python is great, and Java is also good.'
matches = re.findall(r'(Python|Java)', string)
print(matches)
上述代码使用re.findall
函数和正则表达式(Python|Java)
在给定字符串中查找所有匹配的Python
或Java
,并将结果以列表形式输出。
输出结果类似:
['Python', 'Java']