We’re trying to replace integer values with float values in a String, for example:
#var1 * #var2/ 1+100 - 2 + 1.5 - .5
The regular expression should match 1, 100 and 2, but not numbers which are already floats, eg 1.5 and .5
I’ve gotten as far as /[^\w](\d+)/, which finds digits by themselves.
Now, how do I exclude numbers from this regular expression, that are followed by \.?\d+?
The RegEx should work in Java or Actionscript 3.
This will work in Java:
/(?<![.\w])\d+(?![.\w])/. It uses both lookahead and lookbehind to stop matching digits that are either preceeded or succeeded by a dot/letter.