nissedanielsen
nissedanielsen

Reputation: 41

PowerShell Adding "-" between every third char in string

Hello I'm new with PowerShell. I have a string that I'm trying to add an "-" between every third char.

00255D413701 -> 00-25-5D-41-37-01

Anyone has an idea how to do this the easiest way?

Upvotes: 0

Views: 231

Answers (1)

Santiago Squarzon
Santiago Squarzon

Reputation: 60518

(?<=\G.{2})(?!$) might do the trick using and -replace:

'00255D413701' -replace '(?<=\G.{2})(?!$)', '-'

See https://regex101.com/r/MWOSie/1 for details.

Upvotes: 1

Related Questions