Replace multiline

Hi there I need help to replace a string with a begin and end tag. Multiline is possible.
Here is my source string:

<table><tr><td>
<a href="../../index.htm">
<img align=right border=0 src="../../images/edef.gif" HEIGHT=50 WIDTH=50></a>
</td>
<center>


and I woukd like to have:

<table><tr>
<center>


I tryed this but this is not working :frowning: 
`-replace '(?m)<td>.*?<\/td>', 'newString'`

Thanks for any help

Ossy

Hello. What does “not working” mean exactly? Also, you show a string and then a replace snippet, but you don’t show how you used those together. Please edit your post to demonstrate clearly what you execute, what happens (or doesn’t happen), and what you expect in the end.

Ty

Hopes it’s better now

Sorry

Unfortunately, it is not. Based on your post it would appear you are executing the following

<table><tr><td>
<a href="../../index.htm">
<img align=right border=0 src="../../images/edef.gif" HEIGHT=50 WIDTH=50></a>
</td>
<center>

-replace '(?m)<td>.*?<\/td>', 'newString'

Which is not valid powershell code. You should copy and paste your actual code (removing any private information) into a preformatted text block (hit the </> icon and paste your code)

There are a number of ways you could be attempting to replace the text. Without showing what you’re actually executing, you may at best get a blind recommendation based on assumptions like the following.

Assuming you have the “string” in a variable, the following should work. Note that the (?m) modifier treats the input as a string array so the match and replace will be compared to each line individually. What I believe you really want is (?s) which treats the input as a single string.

$variable -replace '(?s)<td>.*?<\/td>', 'newString'

However you would end up with the following instead of what you showed you expect.

<table><tr>newString
<center>

Note the second portion is optional which makes these two commands equal

$variable -replace '(?s)<td>.*?<\/td>'

$variable -replace '(?s)<td>.*?<\/td>', ''

Hopefully that helps. Please actually show the code you are executing that is not working for further assistance.

Perfect !!! Thanks a lot.