Shahzeb Khan
Shahzeb Khan

Reputation: 3642

Regular expression to extract special number

How can i write a regular expression to extract the "integer+W" value

100W abc
60W cde
40W G9
60W CA2

The out put will be

100W 60W 40W 60W

Upvotes: 0

Views: 89

Answers (2)

Dan Ross
Dan Ross

Reputation: 3691

/\b\d+\a+/ matches only numbers that have units e.g. 100mA, and not words with digits inside of them e.g. x4a.

Upvotes: -1

Tushar
Tushar

Reputation: 8049

[0-9]+W

That should do it. Here's a breakdown, in case you want it:

[0-9] (matches the range 0-9 [aka the digits])

+ (asks for 1 or more of the previous match [one or more digits, aka an integer])

W (self-explanatory)

Upvotes: 2

Related Questions