On 2026-03-24 21:12, Artyom Bologov wrote:
Expected result: text in curly braces

The behavior of your script:

H
g/<div class=note.*/s//{/\
/<\/div.*/s//}/
,p
Q

is the same across versions of ed that I have access to. That includes
Solaris, which is "traditional" ed.

In order for your script to work as you expect, the global command
search would have to be run each time after the global command list is
executed. But if the command list changes dot (as in your script),
it's not obvious where the next global command search should begin.

To avoid this ambiguity, the global command first marks all lines in
the given range that match the global search. Then, with dot set to
each matching line, the global command list is executed. This could be
spelled out more clearly in the manual.

In your script, the "default" regex is `/<div class=note.*/' only the
first time the first `s//' is run. At the second global match, the
"default" regex is now `/<\/div.*/'.

I tried to document how regular expressions are shared between
commands here:

https://github.com/slewsys/ed?tab=readme-ov-file#repeated-substitution-modifiers

I'll expand that to cover global commands as well.  Thank you for reporting!

Reply via email to