tmajor99
asked on
Regular Expression - Extracting numeric decimal and Integer from string
I need help with regx expression below. Currently it will only find numeric decimal values but I need both a integer check and numeric decimal check.
.*?([\-\+]?(\d+\.\d+KW|\d+ |\.\d+))\D *
For example:
Input Data Result
Dual Rated - 240V/3.5KW & 208V/2.5KW = 3.5KW --> this works now.
Dual Rated - 240V/5KW & 208V = 5KW --> Expression above does not detect integer values.
5KW = 5KW --> Expression above does not detect integer values.
5.6KW = 5,6KW
0.0 = [null]
5 = [null]
.*?([\-\+]?(\d+\.\d+KW|\d+
For example:
Input Data Result
Dual Rated - 240V/3.5KW & 208V/2.5KW = 3.5KW --> this works now.
Dual Rated - 240V/5KW & 208V = 5KW --> Expression above does not detect integer values.
5KW = 5KW --> Expression above does not detect integer values.
5.6KW = 5,6KW
0.0 = [null]
5 = [null]
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
That regex has a few issues:
The only real reason to keep the beginning .*? is if the regex needs to be anchored to the beginning for some reason.
- missing the capture
- missing the optional sign
- will only pick up a single decimal digit
The only real reason to keep the beginning .*? is if the regex needs to be anchored to the beginning for some reason.
Open in new window