javascript - JS Replace String starting with space and ending with space or comma or dot with another string -
i know basic javascript regex. confused lookheads. title says, want replace word word if ends space
, dot(.)
or comma(,)
eg: replacing "his"
"her"
in following text
"xyz his, his."
to
"xyz her, her."
input.replace(/\b([hh])is(?=[., ])/g, '$1er')
lookahead 0 width assertion check not match input..
with above regex matching his
followed [., ]
..
\b
word boundary let match individual words..
Comments
Post a Comment