Splitting text to grab @strings to make some tags

63 views
Skip to first unread message

dieg...@gmail.com

unread,
Apr 7, 2021, 9:12:27 PMApr 7
to TiddlyWiki
Hello friends,

I'm trying to take an input field that looks like:

this is some     aribrart text .. .etc. # ... @title1   @title2   @[[title with space]]

and parse it to tag another created tiddler with title1, title2 and [[title with space]].

Ive tried playing around with splitting by space, regexp for '@', etc but I cant seem to cleanly grab all titles.

Any help would be greatly appreciated!

Thanks,
Diego

Saq Imtiaz

unread,
Apr 8, 2021, 12:43:41 AMApr 8
to TiddlyWiki
Try this to get the tags (skip the enlist-input[] to keep them as one string):

<$vars text="""@title1   @title2   @[[title with space]]""" reg="""@(\[\[.*[^\]]\]\]|\S+)""">

{{{ [<text>search-replace:gi:regexp<reg>,[$1]enlist-input[]] }}}

</$vars>

I've played around with converting #title to tags in Streams using a similar technique.

Saq Imtiaz

unread,
Apr 8, 2021, 2:28:56 AMApr 8
to TiddlyWiki
I realized that the solution I posted above only works for my use case where the tags are on a line of their own.

I am sure someone with better RegExp prowess can improve on this significantly, but this should work:

<$vars text="""this is some     aribrart text .. .etc. # ... @title1   @title2   @[[title with space]]""" reg="""(?:(?:@(\[\[.*[^\]]\]\]|\S+))|(?!@)\S+|\s)""">

{{{ [<text>search-replace:gi:regexp<reg>,[ $1]enlist-input[]] }}}

</$vars>

TW Tones

unread,
Apr 8, 2021, 4:33:04 AMApr 8
to TiddlyWiki
Diego,

Try this below, notice the subtle difference in annotation for the spaced tiddler? Then in the remove prefix we are talking about the tiddlername.

\define input() aribrart text .. .etc. # ... @title1   @title2   [[@title with space]]

{{{ [enlist<input>prefix[@]removeprefix[@]] }}}

Regards
Tones

Saq Imtiaz

unread,
Apr 8, 2021, 4:46:42 AMApr 8
to TiddlyWiki
{{{ [enlist<input>prefix[@]removeprefix[@]] }}}

is identical to {{{ [enlist<input>removeprefix[@]] }}}

Depending on how the input text will be used, the change in syntax may have significant consequences for rendering of links, finding backlinks and freelinks etc.

Reply all
Reply to author
Forward
0 new messages