我寫一個正則表達式表達式提取的符號(#/ - ),接着是word.For例如,考慮串正則表達式中提取多個符號,隨後字在字符串-python
s= "the amount is 5/10 of the original. The #2 number should be extracted on the dd/yy"
表達正則表達式是
r= re.search(r'(/|#).*\\s+',s)
其中我得到用於上述的輸出是無在哪裏,因爲我預期它顯示
/10 #2 /yy
我的正則表達式有什麼問題。
首先,你的正則表達式是錯誤的;其次,如果沒有發現匹配,如果發現匹配的正則表達式對象re.search返回無。改用re.findall()。 –
@BhawandeepSingla:我知道我的正則表達式有問題。這是它返回None。由於我不確定有什麼問題,我正在尋求幫助,以便有人能夠指出我的錯誤來幫助我。 – shan