簡體   English   中英

正則表達式字符串不匹配

[英]Regex string doesn't match

我在使用Python將字符串中的數字匹配時遇到麻煩。 盡管應該明確匹配,但甚至不匹配[0-9] [\\d]或僅匹配0 我的監督在哪里?

import re

file_without_extension = "/test/folder/something/file_0"

if re.match("[\d]+$", file_without_extension):
   print "file matched!"

閱讀文檔: http : //docs.python.org/2/library/re.html#re.match

如果字符串 開頭為零個或多個字符

您想使用re.search (或re.findall

re.match被“錨定”到字符串的開頭。 使用re.search

使用re.search而不是re.match。

暫無
暫無

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

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