[TW5] regexp

252 views
Skip to first unread message

John

unread,
Aug 15, 2015, 3:32:44 AM8/15/15
to TiddlyWiki

Filter search using search[{{}}] shows a tiddler about transclusion.
But Filter search using regexp[{{[a-zA-Z0-9]*}}] does not yield the same result.

Why not?

Eric Shulman

unread,
Aug 15, 2015, 4:20:50 AM8/15/15
to TiddlyWiki
On Saturday, August 15, 2015 at 12:32:44 AM UTC-7, John wrote:
Filter search using search[{{}}] shows a tiddler about transclusion.
But Filter search using regexp[{{[a-zA-Z0-9]*}}] does not yield the same result.

1) you need to search in the correct field

By default, search[{{}}] look in both the tiddler title and content.  There is one tiddler, [[Transclusion Basic Usage]] that contains the literal "{{}}".
However, regexp[{{}}] defaults to only the title field, and there are no tiddler *titles* that include the curly braces, thus no results.

To apply a regexp filter on the tiddler content, you need specify the desired field by writing regexp:text[...]

2) The documentation in http://tiddlywiki.com/#regexp%20Operator says this:
"The filter syntax makes it impossible to directly specify a regular expression that contains square brackets. The solution is to store the expression in a variable. See the examples."

Thus, to run the filter you want, you can't use the Advanced Search/Filter tab.  Instead, you need to write something like this into a tiddler:
<$set name="pattern" value="{{[a-zA-Z0-9]*}}">
<<list-links "[regexp:text
<pattern>]">>
</$set>

Hope this helps,

enjoy,
-e
Eric Shulman
ELS Design Studios
TiddlyTools - "Small Tools for Big Ideas!"
InsideTiddlyWiki: The Missing Manuals

YOUR DONATIONS ARE VERY IMPORTANT!
HELP ME TO HELP YOU - MAKE A CONTRIBUTION TO MY "TIP JAR"...

Professional TiddlyWiki Consulting Services...
Analysis, Design, and Custom Solutions:

John

unread,
Aug 15, 2015, 7:04:12 AM8/15/15
to TiddlyWiki
Thanks for the explanation.

PMario

unread,
Aug 15, 2015, 12:18:37 PM8/15/15
to TiddlyWiki

hexa...@gmail.com

unread,
Oct 10, 2020, 4:06:50 AM10/10/20
to TiddlyWiki
Thanks a lot.

But further, if I want to catch the match like this:

```
<$set name="pattern" value="{{the (.*?) thing}}">

<<list-links "[regexp:text<pattern>]">>
</$set> 
``` 
How can I get the (.*?)'s value?

Eric Shulman

unread,
Oct 10, 2020, 4:50:51 AM10/10/20
to TiddlyWiki
On Saturday, October 10, 2020 at 1:06:50 AM UTC-7, hexa...@gmail.com wrote:
Thanks a lot.
But further, if I want to catch the match like this:
```
<$set name="pattern" value="{{the (.*?) thing}}">
<<list-links "[regexp:text<pattern>]">>
</$set> 
``` 
How can I get the (.*?)'s value?

The TWCore regexp[...] filter only tests for a match, but doesn't support extracting "grouped" text matches (i.e., embedded patterns surrounded by parentheses).

However, there is an add-on filter named regexps[...] (the "s" is for string) that DOES return the matching group(s)...


If you copy the above code into a tiddler (e.g., $:/filters/regexps.js) and then save-and-reload, you can then use regexps:text<pattern> to get the matched text.

enjoy,
-e
Reply all
Reply to author
Forward
0 new messages