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

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -