brownie brownie - 1 year ago 113
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download