regex - Replace multiple dots in string with different character but same amount -
i have string following "blaa...blup..blaaa...bla."
every part there more 1 dot must replaced "_" must have same amount replaced chars.
the string should result in: "bla___blup__blaaa___bla."
notice last dot not replaced has not other dots "connected".
i tried using following regex approach in powershell legnth of 2 match regardless if there 3 or more dots:
$string -replace '(.)\1+',("_"*'$&'.length)
any ideas?
you can use \g anchor glue match previous.
\.(?=\.)|\g(?!^)\.
\.(?=\.)
match period if 1 ahead.|\g(?!^)\.
or replace period if there previous match (but not start)
replace underscore. see demo @ regexstorm
Comments
Post a Comment