Regex replacement issues -
https://www.myregextester.com/?r=6fba8b94
regex is
(\w(s)\b) sample word
dress - \1 returns "dress"
- \2 returns "dres"
so figured:
- \1 \2 return "dress dres"
but returns:
"dress s" how can make return "dress dres"
first, use + quantifier \w match 1 or more word characters (you match 1 \w). why s , s (see your regex in action capturing ss group 1 , s group 2).
and use:
(\w+)s\b with \0 \1 replacement \0 backreferences whole match, , \1 backreferences captured (\w+). see demo here.
or, if perl, use ((\w+)s)\b , replace \1 \2 (see demo).
see demo
Comments
Post a Comment