繁体   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