Another version of regexps to play with. This version will pull out all 
matches at once when the global flag is used. So the filter could look like:

"[<currentTiddler>get[text]regexps[(?g)#\w+\b]tolower[]]"

It might not make a difference in this use-case, but perhaps in some other 
situation. 

Notes: 

The inverse function (!regexps) still does whatever (!regexp) does. 

Regular expressions in javascript can return sub-groups for non-global 
expression searches. It might be possible to implement this in regexps, if 
someone can think of a good use-case. Mostly, instead of "removeprefix" and 
"removesuffix", you could grab whatever text you wanted from the middle of 
a tiddler title or filter stream. You could even make a single title (or 
field) split into multiple filter outputs. Once again -- what would be a 
use-case?

Have fun,
Mark



On Wednesday, August 23, 2017 at 11:19:35 AM UTC-7, @TiddlyTweeter wrote:
>
> Over in another thread 
> <https://groups.google.com/forum/#!topic/tiddlywiki/4hE3-KUOqkY> I 
> finally got to understand filters better. And, thanks to Mark S., achieved 
> what I needed to do.
>
> HOWEVER.
>
> I feel slightly diminished. I am crap with computers. But one thing I know 
> well is Regular Expressions. I was surprised at the very complex loops that 
> i had to go through to CHANGE stuff in the way I needed to in that thread. 
>
> Let me give an example ...
>
> <$set name=test filter="
> [list[!!text]prefix[#]]
> [list[!!text]prefix[#]removesuffix['s]] +[!suffix['s]]
> [list[!!text]prefix[#]removesuffix[.]] +[!suffix[.]]
> [list[!!text]prefix[#]removesuffix[...]] +[!suffix[...]]
> [list[!!text]prefix[#]removesuffix[,]] +[!suffix[,]]
> [list[!!text]prefix[#]removesuffix[;]] +[!suffix[;]]
> [list[!!text]prefix[#]removesuffix[:]] +[!suffix[:]]
> [list[!!text]prefix[#]removesuffix[!]] +[!suffix[!]]
> [list[!!text]prefix[#]removesuffix[?]] +[!suffix[?]]
> [list[!!text]prefix[#]removesuffix[--]] +[!suffix[--]]
> [list[!!text]prefix[...#]removeprefix[...]] +[!prefix[...]]
> [list[!!text]prefix[--#]removeprefix[--]] +[!prefix[--]]
> ">
>
> Here is sample data this deals with ...
>
> left alone - #buddha #buddha #buddha 
> remove apostrophised ending - #BuddHA's 
> remove fullstop - #buddha. 
> remove comma - #buddha, 
> remove semicolon - #buddha; 
> remove colon - #buddha: 
> remove exclamation mark - #buddha! 
> remove question mark - #buddha? 
> remove 2 trailing dashes - #buddha-- 
> remove 3 trailing stops - #BUDDHA... 
> remove 2 leading dashes - --#Buddha 
> remove 3 leading stops - ...#Buddha 
> left alone - #notBuddha 
> #BuddhaDANGER" (NOT YET DEALT WITH)
> left alone #karma
>
>
> In JavaScript Regular Expressions ALL these cases, and more---discarding 
> the cruft of punctuation that all that code in the first box has to deal 
> with---would be matched by simply: *"#\w+\b"*. Nothing more would be 
> needed.
>
> If you could just transfer the match you would not have any of that 
> prefix/suffix malarky to cope with.
>
> WHY is it SO difficult in TW to do that? 
>
> It seems nuts.
>
> I am aware there is a regexp operator, but can it RETURN its exact match 
> for processing, or is it what it looks like: a match with something IN a 
> field it adds to a list to display but then the match itself is discarded?
>
> All of this is as long way of saying two things ...
>
> (1) Regular Expressions (BOTH match & replace) are natural TW allies
>
> (2) I don't understand why we don't have a more friendly relationship with 
> them.
>
> Please ask if anything is unclear.
>
> Best wishes
> Josiah 
>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/7b3a2c3b-1459-42e7-863c-faeb024b9809%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Attachment: $__core_modules_filters_regexps.js(1).json
Description: application/json

Reply via email to