簡體   English   中英

Python:除逗號以外的正則表達式模式

[英]Python: regular expression pattern other than a comma

除了特殊字符外,如何設置正則表達式模式?

import re
str = 'abc?, def/ghi'
match = re.findall(r'[anything other than ',' or \s]', str)

print(match)
['abc?', 'def/ghi']

謝謝!!!

直截了當呢

[^,]

就是你說的意思 您甚至還不願意閱讀正則表達式文檔嗎? ;-)

對於除逗號和空格以外的所有內容,您可以使用相同的方法:

[^,\s]

要獲得這些序列,請使用以下命令:

[^,\s]+

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM