gpt4 book ai didi

.net - Powershell正则表达式用于随机除以回车符的字符串

转载 作者:行者123 更新时间:2023-12-03 00:48:09 24 4
gpt4 key购买 nike

我正在文本块中寻找IP字符串,该字符串通常会将IP地址除以回车符。例如...

 e c t i o n                  
1 9 2
. 1 6 8 . 1 . 2 5 0 S t a t i o n

我想匹配整个IP地址。我尝试过像...一样积极的向前/向后看
(?<=1 9 2)\S+?(?=2 5 .)

有什么想法吗?

最佳答案

回车符只是另一个空格字符(\s)。

您可以使用1-3位数字的非捕获组((?:pattern)),后跟空格以匹配整个ip:(?:(?:(?:\d\s+){1,3})\.\s+){3}(\d\s+){0,2}\d

$string = @"
e c t i o n
1 9 2
. 1 6 8 . 1 . 2 5 0 S t a t i o n
"@

$Match = $string |Select-String '(?:(?:(?:\d\s+){1,3})\.\s+){3}(\d\s+){0,2}\d'
$IP = $Match.Matches.Value -replace '\s+'

关于.net - Powershell正则表达式用于随机除以回车符的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37822726/

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