Regular Expressions in filters ... VARIANT methods & WEIRDNESS

157 views
Skip to first unread message

@TiddlyTweeter

unread,
Sep 25, 2019, 8:11:43 AM9/25/19
to TiddlyWiki
The flex of TW filter syntax is RICH, USEFUL, DAUNTING & WEIRD. 

Taking Regular Expressions as an example... Five ways to match titles using regular expressions in TiddlyWiki Advanced Search filters. 

The various TW operators provide several ways to match. 

They are not all fully documented. 

And they do NOT work all the same way. BUT ...

Example Tiddler Titles beginning "b or B" 
... in TiddlyWiki.com Advanced Search: Filter. 

ALL produce the same result.
 
Search Operator -- case insensitive by DEFAULT
[search:title:regexp[^b]]

Field Operator -- variant case match via CHARACTER CLASS (NOTE: variable NOT needed for [...] brackets for Character Class)
[field:title/^[bB]/]

Regexp Operator -- case insensitive via FLAG
regexp:title[(?i)^b]]

Regexp Operator -- variant case match via capturing group ALTERNATION
[regexp:title[^(b|B)]]

Regexp Operator -- match using VARIABLE
[regexp:title<var-b-first>]
You need create a global macro (Tiddler named anything, tagged ... $:/tags/Macro) containing ...
\define var-b-first() ^[bB]

TT

@TiddlyTweeter

unread,
Sep 25, 2019, 8:13:31 AM9/25/19
to TiddlyWiki
Repeat for email ...

TonyM

unread,
Sep 25, 2019, 8:48:22 AM9/25/19
to TiddlyWiki
TT

Is this many ways to skin a cat an argument in favor of [prefix[b]]

I do see the value of regex and its on my list of must learn but it does help me understand what people with dyslexia face. Every characters meaning changes according to most of the characters that follow or proceed it. There is a hump one must get over before reading regex does not confuse the reader.

What is critical in my view is to show when regex does a job that can not be done with the standard operators, or does it better.

Regards
Tony

@TiddlyTweeter

unread,
Sep 25, 2019, 9:11:27 AM9/25/19
to TiddlyWiki
Ciao TonyM

There are other ways to skin-the-cat, for sure. And a lot of implicit "behind-the-.scenes" regex in TW is not documented.

Regex takes time. But it is not a dyslexic problem really. 

It is simply it is just not so obvious to anyone.

Best wishes
TT

Mark S.

unread,
Sep 25, 2019, 10:40:45 AM9/25/19
to TiddlyWiki
regex is like a little, tiny condensed programming language. You can do a lot with just a couple hour's study.

I never got to the point of understanding "look-ahead" and "look-behind" features, but there's a lot you can do with just the basics.

prefix[b] will tell you if there's a string starting with letter "b", but it won't tell you if there's a word in the middle of the string that starts with "b".

This could form the basis if you wanted, for instance, to alphabetize all the words in a Shakespeare sonnet.

Thanks!

Cd.K

unread,
Sep 25, 2019, 11:41:12 AM9/25/19
to tiddl...@googlegroups.com
I would use regex much more often once I have solved this fundamental question:

How to combine with logical AND in RegExp?

For logical OR it's as easy like this:

pattern_a|pattern_b

This means literal searching for "pattern_a" OR "pattern_b".


For the AND case I have worked out the following: 

(?=.*pattern_a)(?=.*pattern_b)


Is AND easier to encode?


@TiddlyTweeter

unread,
Sep 25, 2019, 4:20:22 PM9/25/19
to TiddlyWiki
Lookaheads are neat when needed. 

They will not make regex any easier to encode.

WHY do you need them? 

I'd be intrerested to see the data match!

Best wishes
TT

Cd.K

unread,
Sep 25, 2019, 5:27:08 PM9/25/19
to tiddl...@googlegroups.com
@TiddlyTweeter

I open my TiddlyWiki in firefox with a profile that uses the firefox add-on "Export Tabs URLs".
This add-on extracts title and URL e.g. for this web site as follows:

[[Regular Expressions in filters ... VARIANT methods & WEIRDNESS - Google Groups |https://groups.google.com/forum/#!topic/tiddlywiki/l-OSoKg4j4E]] <br/>



25-09-_2019_23-09-09.png


At the red arrow, I can reduce the selection with RegExp from the offer of all opened tabs in this firefox profile to usually one URL.

I want to type as little as possible, but sometimes I need an AND to be able to reduce similar pages to one.

(To select e.g. the third opened tab I have to type reg)

Regards
Cd.K
Reply all
Reply to author
Forward
0 new messages