-4

I have an essay as a big string with letters and numbers (as page numbers) (only single digit and double digits). I want all of them to be replaced by "#". I tried str.replace(/[0-9]/g,"#"), this worked for 0 to 9 numbers, but with the double digits, they were replaced by "##", so how can I replace them all with a single "#"?

1 Answers1

2

If you want to replace only 1 or 2 digits in a line:

str.replace(/[0-9]{1,2}/, "#")

If you want to replace all digits in a line:

str.replace(/[0-9]+/g, "#")
sit
  • 360
  • 3
  • 9