It depends on what regex method you are using.
If you use the .NET Regex::Match
, there is a third parameter where you can define additional regex
options. Use [System.Text.RegularExpressions.RegexOptions]::Singleline
here:
$html =
@'
<li> test </li>
</ul>
'@
$regex = '(^.*<li>.*\</ul>)'
[regex]::Match($html,$regex,[System.Text.RegularExpressions.RegexOptions]::Singleline).Groups[0].Value
If you want to use the Select-String cmdlet, you have to specifiy the singleline option (?s)
within your regex
:
$html =
@'
<li> test </li>
</ul>
'@
$regex = '(?s)(^.*<li>.*\</ul>)'
$html | Select-String $regex -AllMatches | Select -Expand Matches | select -expand Value