I have this regex to match:
(\<div class=\"(?:right).*)(\<p)
This is the input string:
<div class='mid'>Nov 11, 2016</div>
<div >xxx yyy zzz<p>11/11/16 - 13:41</p></div>
It matches OK. I want to insert \n
into the replacement so that <p>
is in another line, but couldn't find a way.
These all fail:
$1\n$2
$1\\n$2
$1`n$2
$1``n$2
"$1`n$2"
I know, in Powershell, quote with backtick can used for this regex. "xxx `n yyy"
. But how to do that in RegexStorm page?
Had tried inserting
\\n
`n
``n
`\n
CodePudding user response:
As you already know, in PowerShell you can use the escape sequence `n
in an expandable string literal to insert a line break:
$inputString -replace '(\<div class=\"(?:right).*)(\<p)',"`$1`n`$2"
For the form on RegexStorm.net, simply put a literal linebreak (hit the ENTER key on your keyboard) between two replacement references, eg $1<linebreak goes here>$2
:
$1
$2
Screenshot of linebreak in replacement:
This also works in PowerShell: