javascript - regex to remove characters at end of word only - js -


i trying remove exclamation marks @ end of word.

eg. remove("!!!hi !!hi!!! !hi") === "!!!hi !!hi !hi"

i able remove exclamation marks, unable target @ end of word.

the following have.

function remove(s){   return s.replace(/([a-z]+)[!]/ig, '$1'); } 

you can strip off !s @ end of words using following regexp:

"!!!hi !!hi!!! !hi"   .replace(/!+\s/g, ' ')  // removes end of words   .replace(/!+$/g, '')    // removes end of last word 

result: "!!!hi !!hi !hi"


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -