python中正则表达式是什么意思_python – 正则表达式中[^.] *的含义是什么?
生活随笔
收集整理的這篇文章主要介紹了
python中正则表达式是什么意思_python – 正则表达式中[^.] *的含义是什么?
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
我試圖從以下文本中獲得482.75:< span id =“yfs_l84_aapl”> 482.75< / span>
我使用的正則表達(dá)式是:regex =’< span id =“yfs_l84 _ [^.] *”>(.?)< / span>‘它起作用了.
但是我不明白的是為什么[^.] *可以在這里匹配aapl?我的理解是.指除換行符之外的任何字符;和^表示否定者.所以[^.]應(yīng)該是換行符,[^.] *應(yīng)該是任意數(shù)量的新行.然而,這種理論與現(xiàn)實(shí)世界的實(shí)施相反.
任何幫助表示贊賞,并提前致謝.
我使用的python代碼:
import urllib
import re
htmlfile = urllib.urlopen("http://finance.yahoo.com/q?s=AAPL&ql=0")
htmltext = htmlfile.read()
regex = '(.+?)'
pattern = re.compile(regex)
price = re.findall(pattern, htmltext)
print "the price of of aapl is", price[0]
總結(jié)
以上是生活随笔為你收集整理的python中正则表达式是什么意思_python – 正则表达式中[^.] *的含义是什么?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。