membersound
membersound

Reputation: 86925

How to match any digits in front of a certain character?

I'd like to match all digits that are in front of the character K and extract that value.

In the example CARRY18K it would match the 18.

Probably I can only achive this with regex, but how? Is \d+K the right expression here?

Upvotes: 1

Views: 63

Answers (2)

anubhava
anubhava

Reputation: 786289

I'd like to match all digits that are in front of the character K and extract that value.

You should use:

\d+(?=K)

(?=K) is positive lookahead that makes sure that digits are followed by K

Upvotes: 2

Toto
Toto

Reputation: 91518

I'd use something like this:

\d+K

If you want to capture the digits:

(\d+)K

Upvotes: 2

Related Questions