user3541631
user3541631

Reputation: 4008

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%

Upvotes: 0

Views: 145

Answers (1)

Zaelin Goodman
Zaelin Goodman

Reputation: 896

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.

Upvotes: 1

Related Questions