gpt4 book ai didi

regex - PowerShell和RegEx格式

转载 作者:行者123 更新时间:2023-12-02 23:45:06 24 4
gpt4 key购买 nike

::编辑::

经过大量的努力之后,我能够找到一种在所有情况下都适用的解决方案...请考虑以下事项:

$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

注意-第6行包含2个空格以正确获得缩进。

这正是我需要的输出!感谢Fede让我走上正轨!

前言:我确实意识到还有其他实现最终目标的方法,但是在我目前更大的范围内,我需要以特定方式设置$ subject的格式。

晚上好!正则表达式菜鸟在这里。我试图找到一种格式$ subject的方式,这种方式对于放入Windows .Reg文件中是有效的。至此,使用下面的代码,我能够完全按需返回第一行,但是我在尝试找出如何创建第二个捕获组并在第一个捕获组之后立即返回值的过程中挣扎。

以下是我当前的PowerShell代码。
$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

这将返回以下结果:
"LaunchPermission"=hex:01,00,14,80,64,00,00,00,74,00,00,00,14,00,00,00,30,00,\

从这一点出发,我需要弄清楚如何创建第二个捕获组,以便它包含其余十六进制对,然后可以将其应用于其他格式。

最终目标是使$ result像这样返回(对于通过$ 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

有什么想法吗?

最佳答案

我不确定这是否是您想要的。

使用此正则表达式:

(.{1,78},)(.{1,78})

您可以检查此 working demo

关于regex - PowerShell和RegEx格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25172694/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com