Xavier,
I know that matching text spanned accross multiple lines with line breaks
can be tricky (if possible)
not only in PowerShell, but this works (so I guess it's possible):
PS:23 >$hs = @"
power
shell
rocks!
"@
PS:24 >$new = $hs -replace "power`nshell","once again, powershell"
PS:25 >$new
once again, powershell
rocks!
Can you post a sample text with the regex pattern?
-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog:
http://blogs.microsoft.co.il/blogs/scriptfanatic Quote:
> Thanks for the reply Shay,
>
> I just tried `n and it does work in strings, but I still couldn't get
> the select-string cmdlet to select a string pattern over multiple
> lines. Actually, I don't know whether select-string is able to do that
> or not (it might only apply the search pattern on each line) or if i'm
> using wrong regular expressions.
>
> Any idea on that ?
>
> Thanks,
> Xavier
> "Shay Levi" wrote:
> Quote:
>> Hi
>>
>> You can use the `n escape sequence:
>>
>> $stringWithLineBreaks = "Power`nShell`nRocks!"
>> $stringWithLineBreaks
>> Power
>> Shell
>> Rocks!
>> -----
>> Shay Levi
>> $cript Fanatic
>> http://scriptolog.blogspot.com
>> Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic Quote:
>>> Hello,
>>>
>>> I am trying to search for a string pattern that includes new lines
>>> with the select-string cmdlet. I was looking for something like \n
>>> to match a new line in the regular expression but I can't seem to
>>> find anything.
>>>
>>> Also, what would be the general syntax to include a new line in a
>>> string (not speaking of regular expressions here) ?
>>>
>>> Any help is appreciated.
>>>
>>> Thanks,
>>> Xavier