How to Ensure That “regexps” Can Always Be Used in TW

I have a recurring problem when regexping in TW: Is there a sure fire “do it this way” to insert the regex in a TW filter operator? I usually mess around until things are solved or I find other solutions but it would be good if there was some kind of “always do this” rule of thumb.

For example, googling these matters often results in recommenations like this but obviously a quare bracket would not be usable directly in a filter operator. The doc regexp Operator (Examples) has this method to overcome, specifically, “square brackets”:

<$set name="digit-pattern" value="[0-9]{2}">
<<list-links "[regexp:title<digit-pattern>]" field:"title">>
</$set>

…but I’m not sure this solves all problems as I don’t think we can escape characters (can we?)

For example, using this regexp service (as shared by @Mohammad -thanks!) I get got this pattern:

(\[.+?\][\s\S]+?)(\n\n) — it is supposed to split a text at every second row (I gave it a sample text)

…and the only way to make sure the created pattern works as expected is to actually see it in action (how else!?)… but the following doesn’t seem to achieve it:

<$let split="(\[.+?\][\s\S]+?)(\n\n)">
<$list filter="""[<mytext>splitregexp<split>]""" >

</$list>
</$let>

…so how am I to know what’s wrong with it… :-/

Mat,
Yes, you have to follow the restriction by TW filters. I expect to get the correct answer from regex.
If I understand you correctly, you mean you have a tiddler with several line of text
and you want to return the odd rows by splitting on even rows e.g. the out should be like
row 1
row 3
row 5

The actual use case:

The idea is to collect all “issues” and stuff that I’ve posted at the TiddlyWiki github repository into a wiki. So the plan is to copy-paste this list) into a wiki and somehow convert it into a titles list. The plan is to rebuild my newtids macro to take the pasted list and show the items as titles.

…so my regexp problem right now is to split this “text”:

[IDEA] InnerWiki widget param to control saving location
#8538 opened 5 days ago by twMat
[BUG] RSOE from decodebase64
#8507 opened 2 weeks ago by twMat
[IDEA] Give custom fields individual selectors based on field name
#8506 opened 2 weeks ago by twMat
...

…into individual issues. A pattern is that each item is two rows (and the second row starts whith #fourdigits) so the first step would be to split after every second row.

[EDIT] Nope, this won’t work…[/EDIT]

This regexp splits lines of text, try with the “multiline” flag: [...]splitregexp:m[...] (untested)

Fred

1 Like

You could use the JSON representation from GitHub and use the JSON filters to iterate over it. Combine that with using tm-http-request to load the JSON and it would always be up to date.

See https://api.github.com/repos/TiddlyWiki/TiddlyWiki5/issues?creator=twMat&state=open

1 Like

How about this solution?

  • the regex generated by Regexer
  • the prompt was: split a multiline text at every second row
<$let split="(.+\n.+)"
      mytext={{Sample Text}} >
<$list filter="""[<mytext>splitregexp<split>] :map[splitregexp[\n]]""" >

</$list>
</$let>

Where Sample Text is a titddler with:

[IDEA] InnerWiki widget param to control saving location
#8538 opened 5 days ago by twMat
[BUG] RSOE from decodebase64
#8507 opened 2 weeks ago by twMat
[IDEA] Give custom fields individual selectors based on field name
#8506 opened 2 weeks ago by twMat
...

testing on https://tiddlywiki.com produces

[IDEA] InnerWiki widget param to control saving location
[BUG] RSOE from decodebase64
[IDEA] Give custom fields individual selectors based on field name
2 Likes

Now that is a super idea! Will see if I can get it to work! That JSON representation even pulls the initial post in the respective issue thread, if I understand it right.

Ah, nice! That does seem to be a viable solution! Thanks!