简体   繁体   中英

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

I have the following regex:

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

and the string:

432 gfd-gfd gfg fd 4445 kk/ t%

For the base is only taking the first letter: g, k. What I want is to extract:

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

The following regex will match any group of characters that does not contain a space or a digit:

[^\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

This matches all of the strings you wanted in your test case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM