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

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -