Regex Replace quotes with Powershell -
Regex Replace quotes with Powershell -
i editing web log files , want remove double quotes feilds, not all.
for example, in next line, want remove double quotes ip address , server.domain.com, leave rest.
2013-02-18 21:47:46.636 post /path/page.html - - "173.194.79.106" "mozilla/4.0 (compatible; msie 6.0; ms web services client protocol 4.0.30319.296)" - "server.domain.com" 200 1079 15
i looping through file loading each line foreach-object
i can line without quotes around ip address this:
[regex]::replace($_,"`"(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})`"", '$1')
so attempted utilize below same server.domain.com item this:
[regex]::replace($_,"`"[a-za-z]*\.[dd][oo][mm][aa][ii][nn]\.[cc][oo][mm]`"",'$1')
and result this:
2013-02-18 21:47:46.636 post /path/page.html - - "173.194.79.106" "mozilla/4.0 (compatible; msie 6.0; ms web services client protocol 4.0.30319.296)" - $1 200 1079 15
what doing wrong?
adding brackets , using (?i)
case-insensitivity:
[regex]::replace( $_, "(?i)`"([a-z]*\.domain\.com)`"", '$1' )
alternatively, utilize -replace
default case-insensitive
$_ -replace "`"([a-z]*\.domain\.com)`"", '$1'
regex powershell
Comments
Post a Comment