How can I code a (REGEX?-) filter that only displays a part of the tiddler?

…that ist to say: It should just show the content until the second appearance of a specified string (in my case <<pic which is my image macro)

You want https://tiddlywiki.com/#splitregexp%20Operator

Old-fashioned approach sans Regex:

(code below image for cut/paste playing)

\define splitter() <pic>
\define adorn() -:-:-:-<pic>
<$let this_raw_text={{{ [[New Tiddler]get[text]search-replace:g<splitter>,<adorn>split[-:-:-:-]first[2]join[]] }}}>
<$wikify name=this_text text=<<this_raw_text>> output="html" >
<pre><$text text=<<this_text>>/></pre>
<<this_text>>
</$wikify>
</$let>
1 Like

Let’s split https://tiddlywiki.com/#Transclusion%20and%20Substitution at the first heading Tiddler Field Transclusion

<$let
   title="Transclusion and Substitution" 
   splitat="\! Tiddler Field Transclusion"
>

{{{ [<title>get[text]splitregexp:m<splitat>first[]] }}}

1 Like

Concidentally, I was posting this link here earlier today for another thread…

Here’s a definition tiddler with extra content (examples, links) that I don’t want included in the glossary list.

The glossary list code is as below, but the crucial line (within the list widget) is:

<$wikify name="firstline" text="""{{{ [<currentTiddler>get[text]splitregexp[\n]first[]] }}}"""><<firstline>></$wikify>

Presumably you can just substitute <<pic for that \n? (The wikify widget is necessary if your target tiddlers include anything beyond text in that initial segment.)

<$list variable="thisTiddler" filter="[tag[definitions]sort[title]]">
<p class="gloss-term">
<$vars taggedCount={{{ [<thisTiddler>tagging[]count[]] }}}>
<$list filter="[<taggedCount>!match[0]then<thisTiddler>]">
@@font-family:"Acme";{{||$:/core/ui/TagTemplate}} @@
@@.ind.hlc.-webkit-column-break-inside:avoid!important;page-break-anside:avoid!important;break-inside:avoid!important;
<$wikify name="firstline" text="""{{{ [<currentTiddler>get[text]splitregexp[\n]first[]]+[removeprefix[:]] }}}"""><<firstline>></$wikify>@@</$list>
<$list filter="[<taggedCount>match[0]then<thisTiddler>]">
@@font-family:"Acme";<$link/>@@ {{!!redirect}}
@@.ind.hlc.-webkit-column-break-inside:avoid!important;page-break-anside:avoid!important;break-inside:avoid!important;
<$wikify name="firstline" text="""{{{ [<currentTiddler>get[text]splitregexp[\n]first[]]+[removeprefix[:]] }}}"""><<firstline>></$wikify>@@</$list></$vars></p></$list>
1 Like

Thank you for the help @Charlie_Veniot @Springer and @CodaCoder
+[splitregexp[<<pic]first[2]join[<<pic]] gets the text… but I guess I need to wikify the result to get the macros to work…

<$let splitteR="<<pic" numbeR="2" currentTiddler="Charles Baudelaire">
<$list filter="[<currentTiddler>get[text]] +[splitregexp<splitteR>first<numbeR>join<splitteR>]" >
<div style="display:block">{{!!title}}</div>
</$list>
</$let>

Interestingly, macros within the tiddler work… but the format
<<<.tc-big-quote

<<<
does not. any ideas with this?

Just for troubleshooting, does it wikify fine if instead of the <<< markdown the tiddler has:

<blockquote class="tc-big-quote">
quote
</blockquote>

This is strange:

<<<.tc-big-quote
Da die photographische Industrie die Zuflucht aller verkrachten Maler war, deren Begabung oder deren Fleiß nicht hinreichten, ihr Studium zu Ende zu führen, so trug diese allgemeine Überschätzung nicht nur das Merkmal der Verblendung und des Schwachsinns, sondern sie hatte auch noch einen Anstrich von Rache. Charles Baudelaire; aus: 
<<<Der Salon 1859

<blockquote class="tc-big-quote">
Da die photographische Industrie die Zuflucht aller verkrachten Maler war, deren Begabung oder deren Fleiß nicht hinreichten, ihr Studium zu Ende zu führen, so trug diese allgemeine Überschätzung nicht nur das Merkmal der Verblendung und des Schwachsinns, sondern sie hatte auch noch einen Anstrich von Rache. Charles Baudelaire; aus: 
</blockquote>

gets:

<<<.tc-big-quote Da die photographische Industrie die Zuflucht aller verkrachten Maler war, deren Begabung oder deren Fleiß nicht hinreichten, ihr Studium zu Ende zu führen, so trug diese allgemeine Überschätzung nicht nur das Merkmal der Verblendung und des Schwachsinns, sondern sie hatte auch noch einen Anstrich von Rache. Charles Baudelaire; aus: << Da die photographische Industrie die Zuflucht aller verkrachten Maler war, deren Begabung oder deren Fleiß nicht hinreichten, ihr Studium zu Ende zu führen, so trug diese allgemeine Überschätzung nicht nur das Merkmal der Verblendung und des Schwachsinns, sondern sie hatte auch noch einen Anstrich von Rache. Charles Baudelaire; aus:

I don’t use “splitregexp” and I’m not really interested in figuring it out.

If it works at all like “split”, then “<<pic” will be removed from the end result, which you don’t want. to happen for the first occurrence of it.

If such is the case, then you’ll want to look at the sample code I gave you to see the trick I apply to not lose that first occurrence.

EDIT: studying your code, I think I understand what you are doing, so I think we can ignore what I wrote above.

I find regex a bit anoying myself when there are often other ways. however the specific usecase spligregexp[\n] is it splits the text on new line. This has so much value in its own right, that if you use it for nothing else this is both useful, and as far as I can see not achivable in any other way.

With this you can spit a text field into seperate lines and use prefix[] and other methods to idfentify or ignore particular lines.

Is there a way to see the unwikified result of the list filter?

Not globally as far as I know, but it depends on what you choose to display for each item. You can often take a variable and use the $text widget to see its true value without wikification.

  • I have come to consider everything in a widget is something to be displayed, if you want something to be subsequently used as a variable, to test or display in a different format like unwikified, define macros and procedures are best used.
  • The exception being wikifying it which is not what you want. Although have a look at the output options in the wikify widget.

Sometime using transclusions can help, transclude a tiddler containing the list widget.

If I examine this more closely I suspect that the filter removes the new lines \n…
How do I avoid this?

Solution to this problem here: How can I build a filter that uses split and join... and does not eat the \n newline characters?