re module的一些紀錄, 持續update
### Common use of the regular expression
\d [0-9]
\s space
\\ '\'
. ''
+ 1 or more than 1
.\ everything
### Code
>>> import re
>>> string = 'Age=20'
>>> re.search('\d+', string).group()
20
>>> import re
>>> string = 'Beautiful, is; better*than\nugly'
>>> string = 'Beautiful, is; better*than\nugly'
>>> # 分隔符號:, ; * \n
>>> list= re.split(',|; |\*|\n', string)
>>> list
['Beautiful', 'is', 'better', 'than', 'ugly']
>>> list= re.split(',|; |\*|\n', string)
>>> list
['Beautiful', 'is', 'better', 'than', 'ugly']
沒有留言:
張貼留言