Discussion:
[tw5] Regexp for matching a tag? (@TiddlyTweeter)
(too old to reply)
Mat
2018-08-08 10:31:00 UTC
Permalink
What is the regexp for matching a tag in the tags field. Should bea basic
use case... but I just don't nail it.

(The @TiddlyTweeter is because I recall Josiah a.k.a TiddlyTweeter has
mentioned he's good at regexps but I of course welcome help from anyone.)

So, for the tag "Foo", the regexp should trigger on all of the following
tags field values (i.e each row is a separate tags field)

Foo Bar Baz

Bar Foo Baz

Bar Baz Foo

[[Foo]] Bar Baz


I.e Foo may or may not be surrounded by space characters - or by double
brackets on both sides.

But it should not trigger when Foo is surrounded by other characters, or
merely double brackets on one side, for example:

NotFoo Bar Baz

Not [[Foo Bar]]

Not [[Foo


...unless, of course, the searched for pattern *does* have one or several
space characters in it, in which case the double brackets are required. E.g
for *Foo Foo* this is OK:

Bar [[Foo Foo]] Baz

...but the following is not because the seached for string had a space in
it which implies there must also be brackets around it

Bar Foo Foo Baz


Thank you!


<:-)
--
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 tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
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/8125baac-dfcb-4f22-82d4-333590a5be70%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
'Mark S.' via TiddlyWiki
2018-08-09 18:32:18 UTC
Permalink
Hi Mat,

You seem to want to look at something like "[[Foo]] Bar Baz" as a whole
string. I'm not sure how to even set that up experimentally, because TW
constantly wants to turn it into a title list, with each item viewed as a
title. As far as a regular expression that just finds "Foo" (assuming a
standard title list) then regexp[^Foo$] should work.

-- Mark
Post by Mat
What is the regexp for matching a tag in the tags field. Should bea basic
use case... but I just don't nail it.
mentioned he's good at regexps but I of course welcome help from anyone.)
So, for the tag "Foo", the regexp should trigger on all of the following
tags field values (i.e each row is a separate tags field)
Foo Bar Baz
Bar Foo Baz
Bar Baz Foo
[[Foo]] Bar Baz
I.e Foo may or may not be surrounded by space characters - or by double
brackets on both sides.
But it should not trigger when Foo is surrounded by other characters, or
NotFoo Bar Baz
Not [[Foo Bar]]
Not [[Foo
...unless, of course, the searched for pattern *does* have one or several
space characters in it, in which case the double brackets are required. E.g
Bar [[Foo Foo]] Baz
...but the following is not because the seached for string had a space in
it which implies there must also be brackets around it
Bar Foo Foo Baz
Thank you!
<:-)
--
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 tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
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/9efe00d1-2990-497c-b5c3-12f9fc51d207%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Mat
2018-08-09 20:14:27 UTC
Permalink
Thanks for reply, Mark!

You seem to want to look at something like "[[Foo]] Bar Baz" as a whole
Post by 'Mark S.' via TiddlyWiki
string. I'm not sure how to even set that up experimentally, because TW
constantly wants to turn it into a title list, with each item viewed as a
title.
I'd think all the cases where you're forced to use the enlist filter
operator would mean that if you don't use it, then the arg is seen as one
string. No?

But, regardless, doesn't the regexp:field[] filter op always interpret any
field content as one string because regexp:tags[oo ba] would show positive
for the tags "foo bar". I.e AFAICT, the space character is just a character
to regexp, not a separator.



As far as a regular expression that just finds "Foo" (assuming a standard
Post by 'Mark S.' via TiddlyWiki
title list) then regexp[^Foo$] should work.
If there is anything more in the field, such as is common the tags field,
then that syntax would give a false negative.

The actual use case for my question is the toggle-in-field
<http://toggle-in-field.tiddlyspot.com/> plugin. I have thus far used
regexp[\b$item$\b] like so

<$list filter="[[$tiddler$]has[$field$]regexp:$field$[\b$item$\b]]">

This is actually pretty good but it gives a false positive in a TW
context(!) where a title Foo must not be confused with a title [[Foo bar]].
There needs to be some condition that a prefixing [[ also requires a
suffixing ]] but I'm not sure how to deal with bracket characters in a
filter and if it is at all possible.

Thanks for your input, Mark!

<:-)
--
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 tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
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/24830f6b-c302-426a-9d26-4b91b33a3288%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Diego Mesa
2018-08-09 20:23:40 UTC
Permalink
Hey Mat,

Just wanted to bring to your attention Tobias' excellent *split* plugin:

https://tobibeer.github.io/tw5-plugins/#split

which might be of interest!
Post by Mat
Thanks for reply, Mark!
You seem to want to look at something like "[[Foo]] Bar Baz" as a whole
Post by 'Mark S.' via TiddlyWiki
string. I'm not sure how to even set that up experimentally, because TW
constantly wants to turn it into a title list, with each item viewed as a
title.
I'd think all the cases where you're forced to use the enlist filter
operator would mean that if you don't use it, then the arg is seen as one
string. No?
But, regardless, doesn't the regexp:field[] filter op always interpret
any field content as one string because regexp:tags[oo ba] would show
positive for the tags "foo bar". I.e AFAICT, the space character is just a
character to regexp, not a separator.
As far as a regular expression that just finds "Foo" (assuming a standard
Post by 'Mark S.' via TiddlyWiki
title list) then regexp[^Foo$] should work.
If there is anything more in the field, such as is common the tags field,
then that syntax would give a false negative.
The actual use case for my question is the toggle-in-field
<http://toggle-in-field.tiddlyspot.com/> plugin. I have thus far used
regexp[\b$item$\b] like so
<$list filter="[[$tiddler$]has[$field$]regexp:$field$[\b$item$\b]]">
This is actually pretty good but it gives a false positive in a TW
context(!) where a title Foo must not be confused with a title [[Foo bar]].
There needs to be some condition that a prefixing [[ also requires a
suffixing ]] but I'm not sure how to deal with bracket characters in a
filter and if it is at all possible.
Thanks for your input, Mark!
<:-)
--
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 tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
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/f77a55ca-9a7d-4f6e-bfbc-fbe1afe67171%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Mat
2018-08-10 11:54:41 UTC
Permalink
While an excellent plugin, I'm not sure exactly how you imagine it used in
this context?

<:-)
--
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 tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
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/b96376a5-158d-4da4-8ceb-18fc64bca65f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
'Mark S.' via TiddlyWiki
2018-08-09 23:09:57 UTC
Permalink
Ok, something to try:

\define removeme() [[$(item2)$]]
\define empty()
<$vars appendme="[[$(item2)$]]">
<$button class="tc-btn-invisible">
<$action-listops $tiddler='$(tiddler)$' $field="$(field)$"
$subfilter="+[append<appendme>]"/>
{{$:/image/checkbox1}} <<label>>
</$button>
<$vars>
\end
\define toggle-in-field(tiddler, field, item, item2, label)
<$set name=item2 value='$item2$' emptyValue='$item$'>
<$set name=label value='$label$' emptyValue='[[$item$]]'>
<$vars tiddler="""$tiddler$""" field="""$field$""">
<div style="white-space:nowrap; display:inline-block; margin-right:3px;">
<$list filter="[enlist{$tiddler$!!$field$}regexp[^$item$$]limit[1]]"
variable=n1 emptyMessage=<<empty>>>
<$button class="tc-btn-invisible" >
<$action-listops $tiddler='$tiddler$' $field="$field$"
$subfilter="+[remove<removeme>]"/>
{{$:/image/checkbox2}} <<label>>
</$button>
</$list>
</div>
</$vars>
</$set>
</$set>
\end

It seems to work with your Foo bar examples, but my testing was pretty
brief. It does NOT use variable #2, because I don't understand yet what you
want to do with that. Perhaps you could explain in more detail.

There was some TW-Logic errors (TW-Logic is not to be confused with the
real thing). This line presents problems:

<$set name=item2 value='$item2$' emptyValue='[[$item$]]'>

Because if there is a value then the rest of the code sees a simple text
string, but if there is not a value than the rest of the code sees a title
list string. The rest of the code needs it to be one or the other. I
switched it off, but then switched on title list right before the list-ops.
This might not be the best way, but it seems to work.

There's only one list widget now. There was a logic error with !regexp.
!regexp returns a list of items that don't match the criteria, but that
doesn't mean that aren't other criteria that DO match the criteria. So
instead I used the "emptyMessage" for when there were no items that
matched. This meant playing with variable names a bit.

HTH
-- Mark
Post by Mat
Thanks for reply, Mark!
You seem to want to look at something like "[[Foo]] Bar Baz" as a whole
Post by 'Mark S.' via TiddlyWiki
string. I'm not sure how to even set that up experimentally, because TW
constantly wants to turn it into a title list, with each item viewed as a
title.
I'd think all the cases where you're forced to use the enlist filter
operator would mean that if you don't use it, then the arg is seen as one
string. No?
But, regardless, doesn't the regexp:field[] filter op always interpret
any field content as one string because regexp:tags[oo ba] would show
positive for the tags "foo bar". I.e AFAICT, the space character is just a
character to regexp, not a separator.
As far as a regular expression that just finds "Foo" (assuming a standard
Post by 'Mark S.' via TiddlyWiki
title list) then regexp[^Foo$] should work.
If there is anything more in the field, such as is common the tags field,
then that syntax would give a false negative.
The actual use case for my question is the toggle-in-field
<http://toggle-in-field.tiddlyspot.com/> plugin. I have thus far used
regexp[\b$item$\b] like so
<$list filter="[[$tiddler$]has[$field$]regexp:$field$[\b$item$\b]]">
This is actually pretty good but it gives a false positive in a TW
context(!) where a title Foo must not be confused with a title [[Foo bar]].
There needs to be some condition that a prefixing [[ also requires a
suffixing ]] but I'm not sure how to deal with bracket characters in a
filter and if it is at all possible.
Thanks for your input, Mark!
<:-)
--
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 tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
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/89e2d4f8-9a78-4bb6-ad73-75a11654e0be%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Mat
2018-08-10 00:21:05 UTC
Permalink
Mark! I need to study your creation more but a first couple of tests look
extremely promising, wow! :-D

Good spotting with the errors too! Will look closer tomorrow.

<:-)
--
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 tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
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/ddabc517-cd73-495b-a317-a702b1eb3383%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
@TiddlyTweeter
2018-08-10 11:22:28 UTC
Permalink
Ciao Mat & Mark S.

As far as I understand TW code: Mark's solution, on first look, is elegant
and economical.

It changes the context in which the regex would run so that the field is
already prepped into lines, one item per line. This makes the regex
appropriately easy.

FYI to go the route of having to regex the content of a field without it
being split down into individual appropriate lines first could involve
unneeded Regex Judo. And maybe needing more than one regex. The code would
get complexer too as "[[...]]" can't be put directly in the regex in TW.
You'd have to do it through a variable (
https://tiddlywiki.com/#regexp%20Operator%20(Examples) last example). And
since "[character class]" is reserved in regex you'd also have to escape
square brackets "[\[\]]".

Worth noting Mark S. also has a PR on Github at for an additional "regexps"
operator https://github.com/Jermolene/TiddlyWiki5/pull/2963.

Best wishes
Josiah
Post by Mat
Mark! I need to study your creation more but a first couple of tests look
extremely promising, wow! :-D
Good spotting with the errors too! Will look closer tomorrow.
<:-)
--
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 tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
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/540f6853-4df5-4249-b4ea-a3fff7ccd135%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Mat
2018-08-10 12:56:16 UTC
Permalink
Post by @TiddlyTweeter
It changes the context in which the regex would run so that the field is
already prepped into lines, one item per line. This makes the regex
appropriately easy.
That's a good take away for me, possibly phrased something like: Regex on
the items after they've been listwidgeted, not the whole input list.
Post by @TiddlyTweeter
Worth noting Mark S. also has a PR on Github for an additional "regexps"
operator https://github.com/Jermolene/TiddlyWiki5/pull/2963
<https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2FJermolene%2FTiddlyWiki5%2Fpull%2F2963&sa=D&sntz=1&usg=AFQjCNEdcZC2trUB3ZWlP8SD_OHci5UEqA>
.
That would in deed be a VERY useful operator. IMO TW is surprisingly
lacking when it comes to tools for programmatically manipulating text.


Thanks for input Josiah, here and privately!

<:-)
--
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 tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
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/6c7920ef-b3de-4818-ba81-ba67dcb7ef61%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Mat
2018-08-10 12:34:23 UTC
Permalink
@Mark

In deed, your code seems to do the job! Excellent and big thanks. I've
updated the code at toggle-in-field <http://toggle-in-field.tiddlyspot.com/>
and added a cred note. I also skipped the item2 parameter - it was too
specific for my own use case.

Now... somewhat annoyingly... look what I just found! github issue #1957; Feature:
Allowing the results of checkbox widgets to be stored in a list
<https://github.com/Jermolene/TiddlyWiki5/issues/1957>

I haven't quite yet figured out if they got it to work, but I see
indications that the tags field would cause problems which is of course
solved in our variant. Wonder if that went anywhere.

<:-)
--
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 tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
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/63af9678-d878-4fa2-9742-7d08c3239c60%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...