brownie brownie - 1 year ago 70
Javascript Question

Remove Number with Regex

i want to remove number at beginning and the end of word in one sentence for example:

"123helo helo123"

then it will return

"helo helo"

I've tried this pattern:


but it just recognized them as one string but not in words. Can you help me?


To answer your question, including specifically where you mention "at beginning and the end of word", this should suffice

str.replace(/\b\d+|\d+\b/g, '')

\b is the word-boundary character. The above removes all numbers directly after or directly before a word-boundary.