Test if a tiddler title is of a particular form

90 views
Skip to first unread message

TonyM

unread,
Jul 13, 2018, 11:45:41 PM7/13/18
to TiddlyWiki
Folks,

I have some tiddlers titled in the form name1.name2.name3

I would like to test any tiddler title to test it is of this form, but not sure how to do so, even after some research

Basically is it three words separated by "." periods
We can assume no other delimiters will be found such as spaces or [[ {{ etc..

I imagine a regex expression can do It, but I have not yet undergone this self education

I want to simply determine if it is true or not and reveal/listWidget some wiki text, 

however one day I may want to extract the three words.

Thanks in advance
Tony

Mark S.

unread,
Jul 14, 2018, 1:43:00 AM7/14/18
to TiddlyWiki
TT is the real expert, but this may get you started:

\define myregexp() ^\w+?\.\w+?\.\w+?$
<<list-links "[regexp<myregexp>]">>

Regexp is SOOO slippery.Without knowing more about your data, and your exact requirements, it's hard to know if this nails it. But you can test and tweak it and see what happens.

If you ever need to extract strings, then you will need something similar to the solution in PR 2963.

-- Mark

TonyM

unread,
Jul 14, 2018, 3:29:01 AM7/14/18
to TiddlyWiki
Mark,

Thanks, that will list all tiddlers with that title form (Exhaustive testing remains)

And the following will reveal if the current tiddler has this form

\define myregexp() ^\w+?\.\w+?\.\w+?$
<$list filter="[is[current]regexp<myregexp>]">


</$list>


Thanks
Heaps

TonyM

unread,
Jul 14, 2018, 3:54:13 AM7/14/18
to tiddl...@googlegroups.com
Mark,

This actually seems to work really well. I always like to return the favour so perhaps you will find this interesting and its implications.

Place the following in a tiddler tagged $:/tags/ViewTemplate
\define myregexp() ^\w+?\.\w+?\.\w+?$
<$list filter="[title<currentTiddler>is[missing]]" variable="missingTiddler">
<$list filter="[{!!title}regexp<myregexp>]">
Tiddler is missing and in w3w format<br>
</$list>
</
$list>
<$list filter="[title<currentTiddler>!is[missing]]" variable="null">
<$list filter="[{!!title}regexp<myregexp>]">
Tiddler is in w3w format<br>
</$list>
</
$list>

Now if a tiddler has a title of the form word.word.word the above will display according to if it exists or not.

Why is this so interesting?
If someone comes to my online wiki using a link such as mywiki.html#test.w3w.example
they will open the tiddler mywiki.html#test.w3w.example if it exists
if it does not exist they will presented with the missing tiddler, which I can code to have a button appear on it, to help the user create the tiddler.

This provides a way to guide a user into creating a tiddler that does not exist by a title they provide, that meets a naming standard. It could be firstname.surname

Regards
Tony


On Saturday, July 14, 2018 at 3:43:00 PM UTC+10, Mark S. wrote:

Mark S.

unread,
Jul 14, 2018, 3:52:44 PM7/14/18
to TiddlyWiki
Application level validation. It will be interesting to see how that works out.

-- Mark

@TiddlyTweeter

unread,
Jul 14, 2018, 8:40:20 PM7/14/18
to TiddlyWiki
Ciao TonyM & Mark S.

Really interesting work.

A few small non-consequential notes on the regex ... This is just for interest.

Marks' ...


^\w+?\.\w+?\.\w+?$

is perfectly serviceable. But it will work simpler too ...

^\w+\.\w+\.\w+$

... The qualifying "?" that is to prevent "greedy" matches is not needed. A greedy match here is fine.

One issue is that \w is shorthand for the JS character class ...

[a-zA-Z0-9_]

This means IF you used, for instance, any accented character it would break.

A way round this would be to add the accented characters to an explicit class. But every one would need explicitly adding. Easier would be to use , instead of \w, a negative character class like [^\.] = its not a full-stop.

The only problem with regex character classes in TW is they get a bit baroque to use as they need square brackets so you can't do them directly -- https://tiddlywiki.com/#regexp%20Operator

Just thoughts

TonyM

unread,
Jul 14, 2018, 10:31:52 PM7/14/18
to TiddlyWiki
Josiah,

I am glad for your help, and marks - I need to jump into regex soon, but it seems to require a lot of rote learning - perhaps I can make a wiki for that?

In the case in question the three words can only be a-zA-Z

What would I replace \w with for this outcome?

Thank
Tony

Mark S.

unread,
Jul 14, 2018, 10:52:55 PM7/14/18
to TiddlyWiki
This should do that:

\define myregexp() ^([a-zA-Z]+\.){2}[a-zA-Z]+$
<<list-links "[regexp<myregexp>]">>

In this example, I'm using groups and a quantifier, since the first match gets repeated twice. You can expand that out if it's easier to scan.

-- Mark

Mohammad

unread,
Jul 14, 2018, 11:17:29 PM7/14/18
to TiddlyWiki
Very good code!
I used this with modification to list all .png tiddlers 

Mohammad
Reply all
Reply to author
Forward
0 new messages