所以我是
Python的新手,并试图通过Google Python在线课程[
https://developers.google.com/edu/python/regular-expressions]
我正在运行Python 2.7.5,当我尝试这个例子时,它与=>有问题.
我已经尝试搜索谷歌的解释,但已经空了.任何帮助,将不胜感激.
错误信息如下.
sandbox$./re-test.py
File "./re-test.py", line 8
match = re.search(r'iii', 'piiig') => found, match.group() == "iii"
^
该计划的代码是:
#!/usr/bin/python
import re
## Search for pattern 'iii' in string 'piiig'.
## All of the pattern must match, but it may appear anywhere.
## On success, match.group() is matched text.
match = re.search(r'iii', 'piiig') => found, match.group() == "iii"
match = re.search(r'igs', 'piiig') => not found, match == None
## . = any char but \n
match = re.search(r'..g', 'piiig') => found, match.group() == "iig"
## \d = digit char, \w = word char
match = re.search(r'\d\d\d', 'p123g') => found, match.group() == "123"
match = re.search(r'\w\w\w', '@@abcd!!') => found, match.group() == "abc"
最佳答案 作者正在使用=>描述结果;它不是Python语法的一部分.
考虑它写如下,其意图可能更清楚:
match = re.search(r'iii', 'piiig') #=> found, match.group() == "iii"