regex正規化取值問題
2019/12/12 08:25 下午
Python網路爬蟲討論版
葉碩涵
觀看數:5
回答數:2
收藏數:1
pycrawler
pycrawler-d11
您好,我對於這個章節還是有很多不懂的地方
比如作業中
regex = '[01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5]'
test_string0 = "216"
RegexMatchingTest(regex, test_string0)
匹配結果=21
6不見了
但是
regex = '([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\.([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\.([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\.([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])'
test_string1 = "Test IP 216.58.200.227"
RegexMatchingTest(regex, test_string1)
匹配結果=216.58.200.22
6又出現了,最後一個數字7不見了。
想請問原因是什麼