1

How do I go about removing all digits and all punctuations in a string using regex?
For example: From Eric-Has555-Books to EricHasBooks

I am trying to use String.replace(), but my regex below doesn't work:

str = 'Eric-Has555-Books'
reg = /[0-9]-/g;
str.replace(reg, '');
LED Fantom
  • 1,229
  • 1
  • 12
  • 32

1 Answers1

0

You can use [^a-z] which says "Remove everything that isn't a letter". This is also known as Negated Character Classes

let r = 'Eric-Has555-Books'.replace(/[^a-z]/gi, '')

console.log(r)
Get Off My Lawn
  • 34,175
  • 38
  • 176
  • 338
  • That question is nine years old and SO standards were different back then. Although I just downvoted it and flagged it as too broad. Thanks. – j08691 Sep 06 '19 at 15:50