Category Archives: between

PowerShell: Find Text between two Words

I need to find out, if there are maxThreads and/or maxConnections configured in the connector port 8080 of tomcat.

example:

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

I tried with regex but poorly failed.

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

Thanks ahead