-2

I have a textfile with results and attendances from various football games. I want to find each number and replace them with a phrase, as well as display the whole textfile.

if($_ =~ s/\d{1,}/TEST/) is my current regex, but it does not find floatnumbers. Any ideas?

karthik manchala
  • 13,492
  • 1
  • 31
  • 55
paulmc
  • 7
  • Use `[\d.]+` to match digits and decimal points. – Barmar May 11 '15 at 11:36
  • @Barmar: that also matches a single period (or any sequence of them). Some examples, please? It's easier when all of your floats have leading digits (`0.1`), for example, and/or you need the period in `100.` – Jongware May 11 '15 at 11:39

1 Answers1

0

I'd use that one:

[-+]?\d+\.?\d*

It takes into account that a number maybe negative. If is not your case, remove the [-+]?

Miguel Prz
  • 13,718
  • 29
  • 42