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

时间:2015-01-27 10:17:52

标签: regex apache tomcat powershell between

如果在tomcat的maxThreads中配置了maxConnections和/或connector port 8080,我需要了解一下。

示例:

<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)

提前致谢

1 个答案:

答案 0 :(得分:1)

这很简单

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