TSE search sub-patterns

14 views
Skip to first unread message

Fred H Olson

unread,
Jan 21, 2026, 12:45:46 PM (9 days ago) Jan 21
to Semware
I've been studying TSE search sub-patterns and have some observations.
The help entry for "Regular Expression Operators" is quoted below.
Note this can be found with "<esc>hireg<cr>" and then scroll down
about 200 lines.

>{ } In a search pattern, serves as a Tag to identify a sub-pattern within
> the full search pattern. Tagged patterns can be nested.
>
> Tags are used to define a group of characters as a sub-pattern so
> that an operator acts on more than one character or character Class.
>
> Tags are also used to identify a sub-pattern within a Regular
> Expression so the sub-pattern can be separately referenced in a
> subsequent replacement. Tagged sub-patterns are implicitly numbered
> from 1 through 9 based on the leftmost "{" symbol. The sub-pattern
> number can be used within a replacement string to reference a tagged
> sub-pattern, using the following format:
>
> \n
>
> where "n" is the actual sub-pattern number from 1 - 9 that
> represents the appropriate tagged sub-pattern. To identify the FULL
> search pattern, "n" is "0" (that is, \0).

The thing I was confused about until today was that tho
> Tagged sub-patterns are implicitly numbered
> from 1 through 9 based on the leftmost "{" symbol.
a TSE Regex is NOT limited to 9 sub-patterns. I verified this
by creating a test file with the numbers 00-22 each on one line
and searched that file with options "igxv" for
{01}|{02}|{03}|{04}|{05}|{06}|{07}|{08}|{09}|{11}|{12}|{13}|{14}|{15}|{16}|{17}
Note that "{10}" and "{00}" are missing. The result is a compressed view with:
"16 occurrences found on 16 lines".

Numbered sub-patterns are only needed for reusing the string that a
sub-pattern finds.
I wonder if depending on the specifics of the replace desired,
maybe one might be able to reorder the sub-patterns in the search pattern to
put the one one wants to replace near the beginning.
Sub-pattern connected by "|" (or) do not depend on order.
I have not found an example.
Doing 2 replaces might be a workaround.

Fred


--
You can fool all the people some of the time and some of the people
all the time, but you cannot fool all the people all the time.

Abraham Lincoln

Trump has proved he can fool enough of the people (aided by circumstances)
to get elected US president. But what happens when his plans and boasts
go awry. For example, mass deportations and huge tariffs will do a number
on the economy. Fred 11/11/24

Fred H. Olson Minneapolis,MN 55411 USA (near north Mpls)
Email: fholson at cohousing.org 612-588-9532
My Link Pg: http://fholson.cohousing.org ybb_

zhong zhao

unread,
Jan 21, 2026, 8:31:52 PM (9 days ago) Jan 21
to SemWare TSE Pro text editor
I test:
the numbers 00-22 each on one line,
Search for:{01}|{02}|{03}|{04}|{05}|{06}|{07}|{08}|{09}|{11}|{12}|{13}|{14}|{15}|{16}|{17}
Replace with:\0
Replace Options:gnx
the result is: Not change.

the numbers 00-22 each on one line,
Search for:{01}|{02}|{03}|{04}|{05}|{06}|{07}|{08}|{09}|{11}|{12}|{13}|{14}|{15}|{16}|{17}
Replace with:\1
Replace Options:gnx
the result is: 02..09,11..17 change to empty line.

the numbers 00-22 each on one line,
Search for:{01}|{02}|{03}|{04}|{05}|{06}|{07}|{08}|{09}|{11}|{12}|{13}|{14}|{15}|{16}|{17}
Replace with:\3
Replace Options:gnx
the result is: 01..02,04..09,11..17 change to empty line.

the numbers 00-22 each on one line,
Search for:{01}|{02}|{03}|{04}|{05}|{06}|{07}|{08}|{09}|{11}|{12}|{13}|{14}|{15}|{16}|{17}
Replace with:\9
Replace Options:gnx
the result is: 01..08,11..17 change to empty line.

Suggestion:
Do not use {foo}|{bar} and {tag1}{tag2} together prevent from unpredictable result.


Reply all
Reply to author
Forward
0 new messages