gpt4 book ai didi

regex - PowerShell:在两个单词之间查找文本

转载 作者:行者123 更新时间:2023-11-28 22:55:31 24 4
gpt4 key购买 nike

我需要找出在 tomcat 的 connector port 8080 中是否配置了 maxThreads 和/或 maxConnections

例子:

<Connector port="8080" protocol="HTTP/1.1"
maxThreads="600"
maxConnections="3000"
connectionTimeout="20000"
redirectPort="443" />

我用 regex 试过了,但很失败。

$file = Get-Content "D:\Program Files\Apache Software Foundation\Tomcat 7.0\conf\server.xml"
$pattern = "(?<=.*protocol=""HTTP/1.1"")\w+?(?=connectionTimeout=""20000"".*)"
$Opts = [Regex]::Match($file, $pattern)

提前致谢

最佳答案

这很简单

PS>[xml]$x=gc "D:\Program Files\Apache Software Foundation\Tomcat 7.0\conf\server.xml" 
PS>$x.xml.Connector.maxConnections
3000
PS>$x.xml.Connector.maxThreads
600

如果你有多个连接器你可以做

$x.xml.Connector | ?{ $_.port -eq "8080"} |select maxthreads  

关于regex - PowerShell:在两个单词之间查找文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28168000/

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