Search code examples
regexregex-greedyed

Non-greedy regex matching in ed (editor)


I am looking at a line of a file I opened with ed and displayed with .p:

First sentence. Another. One. Text continues

Now I want to replace the string First sentence. with replacement. However, the command

.s/.*\./replacement./

acts in a greedy manner, that is, it replaces First sentence. Another. One. by replacement, and not just First sentence. as desired.

How can I do a non-greedy replacement in ed?


Solution

  • I'm not sure if ed supports non-greedy matching, but assuming it does not:

    You want to match everything except a dot.

    .s/[^.]*\./replacement./