Regex insert dash

Hello all,

Just getting started learning regex. I gather for my issue I need to do a capture group to insert a dash. I’ve got a text file and I’ve got instances of numbers like this:

12345601

That need to be

123456-01

Here is what I’ve got so far:

Get-Content 'C:UsersAdminDesktop20181020.txt' | Select-String -Pattern ‘dddddddd’ | ForEach-Object {$_ -replace ‘dddddddd’,‘$1-‘} 

Clearly I’m doing something wrong as I’m just replacing all instances with $1-, but I’m at least matching the numbers I’m looking for!

The first 6 numbers can be any digit but the last two will always be 01, 02, or 03 if that’s of any help.

Any help from you regex gurus would be appreciated.

Thanks.

submitted by /u/lzimbelman
[link] [comments]

Leave a Reply