簡體   English   中英

Python正則表達式:獲取所有非數字,分組,后跟或不跟一個空格

[英]Python regex: get all the non digits, in groups, followed or not by a space

我有以下正則表達式:

(?P<value>[0-9]+)(\s*)(?P<unit>[^\d+? ])

和字符串:

432 gfd-gfd gfg fd 4445 kk/ t%

因為base只取第一個字母: g, k. 我想要的是提取:

gfd-gfd, gfg, fd, kk/, t%

以下正則表達式將匹配任何不包含空格或數字的字符組:

[^\d\s]+

[^   // don't match any characters in this group
  \d // any digit
  \s // any whitespace
]+   // match one or more characters that meet these criteria

這匹配您在測試用例中想要的所有字符串。

暫無
暫無

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

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