Reputation: 65
::EDIT::
After much goofing off, I was able to find a solution that appears to work in all cases... Consider the following:
$subject = '"LaunchPermission"=hex:01,00,14,80,64,00,00,00,74,00,00,00,14,00,00,00,30,00,00,00,02,00,1C,00,01,00,00,00,11,00,14,00,04,00,00,00,01,01,00,00,00,00,00,10,00,10,00,00,02,00,34,00,02,00,00,00,00,00,18,00,0B,00,00,00,01,02,00,00,00,00,00,0F,02,00,00,00,01,00,00,00,00,00,14,00,0B,00,00,00,01,01,00,00,00,00,00,01,00,00,00,00,01,02,00,00,00,00,00,05,20,00,00,00,20,02,00,00,01,02,00,00,00,00,00,05,20,00,00,00,20,02,00,00'
$result = $subject -creplace '(?ism)(.{1,76},)(.{1,75})', @'
$1\
$2\
'@
Write-Host $result
Note - Line 6 contains 2 spaces to get the indenting correctly.
This outputs exactly how I need! Thanks Fede for putting me on the right track!
Preface: I do realize there are other ways of achieving the end goal here, but within my current, larger scope, I need to format $subject in a specific way.
Good evening! Regex noob here. I'm attempting to find a way to format $subject in such a way that it is valid for dropping into a Windows .Reg file. At this point with the code below, I am able to return the first line exactly as I need it, but I'm struggling with trying to figure out how to create a second capture group that returns the values immediately after the first capture group.
Below is my current PowerShell code.
$subject = '"LaunchPermission"=hex:01,00,14,80,64,00,00,00,74,00,00,00,14,00,00,00,30,00,00,00,02,00,1C,00,01,00,00,00,11,00,14,00,04,00,00,00,01,01,00,00,00,00,00,10,00,10,00,00,02,00,34,00,02,00,00,00,00,00,18,00,0B,00,00,00,01,02,00,00,00,00,00,0F,02,00,00,00,01,00,00,00,00,00,14,00,0B,00,00,00,01,01,00,00,00,00,00,01,00,00,00,00,01,02,00,00,00,00,00,05,20,00,00,00,20,02,00,00,01,02,00,00,00,00,00,05,20,00,00,00,20,02,00,00'
$result = $subject -creplace '(?ism)(.{1,78},).*', '$1\'
Write-Host $result
This returns a $result of:
"LaunchPermission"=hex:01,00,14,80,64,00,00,00,74,00,00,00,14,00,00,00,30,00,\
From that point, I need to figure out how to create a second capture group so that it contains the remainder of the hex pairs that I can then apply additional formatting to.
The end goal is to have $result returned like this(for any similar value fed in via $subject):
"LaunchPermission"=hex:01,00,14,80,64,00,00,00,74,00,00,00,14,00,00,00,30,00,\
00,00,02,00,1c,00,01,00,00,00,11,00,14,00,04,00,00,00,01,01,00,00,00,00,00,\
10,00,10,00,00,02,00,34,00,02,00,00,00,00,00,14,00,0b,00,00,00,01,01,00,00,\
00,00,00,01,00,00,00,00,00,00,18,00,0b,00,00,00,01,02,00,00,00,00,00,0f,03,\
00,00,00,00,10,00,00,01,02,00,00,00,00,00,05,20,00,00,00,20,02,00,00,01,02,\
00,00,00,00,00,05,20,00,00,00,20,02,00,00
Any thoughts?
Upvotes: 2
Views: 192
Reputation: 31045
I'm not fully sure if this is what you want.
Using this regex:
(.{1,78},)(.{1,78})
You can check this working demo
Upvotes: 2