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
Post a Comment