Powershell Replace Regex
Posted
by
Brad
on Stack Overflow
See other posts from Stack Overflow
or by Brad
Published on 2012-06-18T00:16:30Z
Indexed on
2012/06/18
3:16 UTC
Read the original article
Hit count: 245
I have a select-string which is seaching an IIS log for a particular string and returning the 2 lines above and one line below. So results look like this:
2012-06-15 18:26:09 98.138.206.39 OutboundConnectionResponse SMTPSVC1 WEB10 - 25 - - 220+mta1083.sbc.mail.ne1.yahoo.com+ESMTP+YSmtp+service+ready 0 0 60 0 218 SMTP - - - - 2012-06-15 18:26:09 98.138.206.39 OutboundConnectionCommand SMTPSVC1 WEB10 - 25 EHLO - WEB10.DOMAIN>COM 0 0 4 0 218 SMTP - - - - > 2012-06-15 18:26:09 74.125.244.10 OutboundConnectionResponse SMTPSVC1 WEB10 - 25 - - 550+IP+Authorization+check+failed+-+psmtp 0 0 41 0 218 SMTP - - - - 2012-06-15 18:26:09 74.125.244.10 OutboundConnectionCommand SMTPSVC1 WEB10 - 25 RSET - - 0 0 4 0 218 SMTP - - - -
Note the third line begins with > denoting thats the line that select-string matched upon.
I am trying to do a -replace on the > to replace it with < font color="red">$1< /font> but my replace doesn't seem to work.
Here's my code: $results = $results -replace "(^> )(.*)$", "< font color='red'>$1< font>"
Can any powershell regex guru's out there tell me why my regular expression isn't matching?
Thanks Brad
© Stack Overflow or respective owner