Is there a way to do a not operator for a PCRE in the PHP preg_replace function? I'm trying to filter a currency string (ex: $1,000.00) down to the float value (1000.00). My thought is to preg_replace on anything that is NOT 0-9 or the decimal point. So, essentially, I want to invert the pattern /([0-9.])/ - is there a way to do that?
Asked
Active
Viewed 3,040 times
1 Answers
3
preg_replace( '/[^0-9.]+/', '', '$1,000.00' )
results in 1000.00.
the caret at the beginning marks that all the characters that aren't in the set (0-9 and a dot) will match and thus will be replaced with nothing.

Esailija
- 138,174
- 23
- 272
- 326