Search and Replace Example - cnt

This is a real life example of the use of cnt.

On my www site I have a list, compiled by him, of my brother's publications. But he needed to add several more entries, not at the end but earlier. So I needed a method to renumber subsequent entries. A typical entry is

<p id="p268">268. <span class="title">“Spelling it out”,</span> Times Higher Education Supplement, 3 December 1999, p. 15.

Using the counter in the obvious way

Search: "<p id=\"p"@1{#}1:3@2"\">"@3{#}1:3@4"."
Replace: @01cnt@23cnt@40

This would replace
<p id="p268">268.
by
<p id="p269">270.>

Which is not what we want. So we have to do it in two steps:

First use the counter to increase the id="number"

Search "id=\"p" @1 {\d}+ @2 "\">"<
Replace @01 cnt @29

and then another replace to copy that number after the first '>'.
Search "id=\"p" @1 {\d}+ @2 "\"~>" @3 {\d}+
Replace @03 @12

Note that it doesn't quite work with the whole page linked above to because of the section <p id="p376">376-378 followed by 376-378 individual links. However in practise all renumbering was nearer to the required result.

If you want to try this you can download the page and get the search and replace strings by exporting this page as text. See Working out Search and Replace expressions

As a footnote - what I had done was to put a TAB character after the <p id="p268">268. on each entry. I could then load the text into PipeDream when all the numbers would be in the first column and could be Shifted up or down to insert a new entry. Only the new entry needs numbering - entries below are Shifted into the correct alignment. The problem is of course that some entries are more than one line so require maual adjustments. Renumbering in StrongED requires less tweaking!

Was this page helpful? Please email me and/or rate this page:


If you want a reply make sure any email address @torrens.org will not get spam-binned!
Optional comment

Other relevant pages

Top of page


Page Information

http://css.torrens.org/valid-html401-bluehttp://css.torrens.org/valid-css Document URI: http://stronged.torrens.org/man/search/examples/counter.html
Page first published Thursday the 28th of December, 2017
Last modified:Thu, 10 Oct 2019 13:12:18 BST
© 2017 - 2024 Richard Torrens.