Hi,
when a pattern for a regular expression contains reserved characters it can be difficult to quote all these signs correctly.
A .NET function helps 🙂
Let us assume you want to parse a HTML Site for download links. The lines with the link have the format
<li><a href="http://cert.mydomain.org/pki/Cert0001.crt" target="_blank">download</a></li>
Characters like “.” or Spaces must be escaped. The function Escape() from the RegEx class helps:
1 2 3 4 5 | $sLink='<li><a href="http://cert.mydomain.org/pki/Cert0001.crt" target="_blank">download</a></li>'$EscapedString=[System.Text.RegularExpressions.Regex]::Escape($sLink)$EscapedString |
And then its simply to extract the download link(all crt files from cert.mydomain.org) :
1 2 3 4 5 6 | $sPattern=''[System.Text.RegularExpressions.Regex]::Match($sLink, $sPattern).Groups[1].Valuehttp://cert.mydomain.org/pki/Cert0001.crt |
Michael