I'm having a problem with a simple Find and Replace in Dreamweaver using a regex.
This is what's in my find box:
<div id="title">([^ö]*)</div>
This is what's in my replace box
<div id="title">
<div class="center">
$1
<span>hello there</span>
</div>
</div>
If I run the find and replace above on this:
<div id="title"><h1>Page title</h1></div>
<div class="content">
more content
</div>
I can't get to this result:
<div id="title">
<div class="center">
<h1>Page title</h1>
<span>hello there</span>
</div>
</div>
<div class="content">
more content
</div>
Because the content of de find box does not define that I only want the content between < div id="title" > and the first < /div >...
Any ideas?
Matching markup languages with regexes is tricky to say the least.
In your case (assuming that the <div> tags you're searching and replacing won't contain any nested <div> tags), you could get by with using
<div id="title">([\s\S]*?)</div>
as your search regex.
[\s\S] matches any character,
including linebreaks (that's more
explicit than [^ö], I'd say). *
matches zero or more of those ?
makes the star "lazy", meaning that
it will match as few characters as
possible - thereby ensuring that the
match will stop at the next </div>.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With