0

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?

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Will Bonde
  • 560
  • 6
  • 19

1 Answers1

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