I assume that the OP wishes to match substrings of the form
abcm
where:
"cm"
is a literal;
"cm"
is not followed by a letter;
"b"
is the string representation of a non-negative float or integer (e.g., "80"
or "80.25"
, but not "08"
or ".25"
); and
"a"
is a character other than "-"
, "+"
and "."
, unless "b"
is at the beginning of the string, in which case "a"
is an empty string.
If my assumptions are correct you could use the following regex to match b
in abcm
:
(?<![-+.\d])[1-9]\d*(?:\.\d+)?cm(?![a-zA-Z])
Demo
The regex engine performs the following operations:
(?<! # begin negative lookbehind
[-+.\d] # match '-', '+', '.' or a digit
) # end negative lookbehind
[1-9] # match digit other than zero
\d* # match 0+ digits
(?:\.\d+) # match '.' followed by 1+ digits in a non-cap grp
? # optionally match non-cap grp
cm # match 'cm'
(?![a-zA-Z]) # match a letter in a negative lookahead
If my assumptions about what is required are not correct it may be evident how my answer could be adjusted appropriately.