RegularExpression-Python
今天有想在這裡分享 Regular Expression,這也是大家不想碰到的,可就是一個很復雜的就越耗用。
我也沒有很勵害,但之前開發自動化,用很多。因此想藉由這編文章來寫下我所寫道的筆記和參考很多教學。
在介紹之前我們在 python 都會用到 re 或是 rex ,但在這我只會分享用 re,也就是要 import re
,不然不能用。
常用的 req module
Module | 說明 |
---|---|
match | Determine if the RE matches at the beginning of the string. |
search | Scan through a string, looking for any location where this RE matches |
findall | Find all substrings where the RE matches, and returns them as a list. |
finditer | Find all substrings where the RE matches, and returns them as an iterator. |
compile()
1 | import re |
output:
None
cheenchih
> >['chenchih', 'ChenChih']
match()
This function matches a regular expression pattern at the beginning of a string. If the pattern is found, it returns a match object, otherwise, it returns None.
1 | import re |