Situation
Here is the Regex & Substitution I used for Regex replace in Dreamweaver::
(( and )|( that )|( include )|( includes )|( including ))
$1<br/>\n
image: settings for Regex Replace in Dreamweaver
2.
After I Replace All
in current document. I found few errors.
eg::
create new Flux and Mono instances
is being replaced into (wrong one)
create new Flux that <br/>
Mono instances
instead of (correct one)
create new Flux and <br/>
Mono instances
( regex101 visualization => https://regex101.com/r/hJTqFg/1 )
Question
Why is this happening?
How can I avoid this? (A safer approach for Replacement?)
Have this happened to you before?
note:
- There are a lot of replacements happened in this document — around 300+ — this document is large.
-
When the replacement process is going. I can see Dreamweaver scroll through the source code quickly.
Instead of just instantly replace all replacements (which is different from what other text editing software would do).
Is this normal?
This makes me suspect that the problem is due to the replacement speed — the lag made Dreamweaver somehow replace the text into the previous replaced one …? — (but idk, idk how internally Dreamweaver is implemented..)
-
(There are only few errors — but still, this should not happen.)
-
(The replacement is specifically for html tag
<p>
(I dont think this is the problem)) -
(More precisely,
the original text is
create new <code class="literal">Flux</code> and <code class="literal">Mono</code> instances
instead of just
create new Flux and Mono instances
(for the sake of readability, I simplified it, but it does not matter).)
-
Using Dreamweaver Version 2021
-
Replacement is on a
.xhtml
file
-
Its not just get replaced into other String (thats in the regex pattern) due to the
|
in regex pattern.There are also mistakes where some characters just get disappeared… (though, this is even more rare)
eg:
blockhound
becomeslockhound
;1.0.1.RELEASE
becomes.0.1.RELEASE
;(I didnt just do 1 regex replace pattern, there are also other patterns that I applied to this document;
though, these 2 eg above, certainly should not be matched in any regex patterns that I used for this document…)
-
I did another regex replace test, by using the option in
(Documents in) Folder ...
, notCurrent Document
— so, the effect of
scrolling
will not present (& this seems process faster)Though, even with this, there are still Errors.
— so, it seems like the occurence of Error has nothing to do with the
scrolling
in regex replace in Dreamweaver.
Below is Simplified example of above (if above contains redundant information)
In short:
0 . you have some text
<p>AA and BB</p>
1 . if you use a regex pattern contains an or
syntax, |
, eg:
(( and )|( that ))
2 . and your replacement contains a capture group $1
, eg:
$1foobar
3 . and you perform an regex replace all in Dreamweaver specific to a tag, say: <p>
(I call it specific-targeting-replacement tag
)
4 .
-
and there is a tag (a tag that is not of type
<p>
), above<p>
, say:<li>
(I call itnon-specific-targeting-replacement tag
) -
and
<li>
contains the wordthat
(thethat
word presents in the regex pattern (withor
syntax) that is adjacent toand
),-
(I call that word
that
asadjacent-replacement word
, -
I call the word
and
asto-be-replaced word
)
-
<ul>
<li>xxxx that xxxx</li>
</ul>
5 . then the text in tag <p>
below that tag <li>
, would be replaced with the wrong String (the adjacent-replacement word
). eg:
it should be replaced into (correct)
<p>AA and foobarBB</p>
but it may be replaced into (wrong)
<p>AA that foobarBB</p>
img: file & procedure to create this error
the testing file:
<!DOCTYPE html>
<html>
<body>
<p>AA and BB</p>
<p>AA and BB</p>
<ul>
<li>xxxx that xxxx</li>
</ul>
<p>AA and BB</p>
<p>AA and BB</p>
</body>
</html>
Best Answer
Here is a solution with Notepad++:
(?:<p>|\G)(?:(?!</p>).)*?\b(?:and|that|includes?|including)\b\K(?=.*?</p>)
foobar
. matches newline
Explanation:
Screenshot (before):
Screenshot (after):