Can a regex operator return the substring that matched?

74 views
Skip to first unread message

S. S.

unread,
Mar 28, 2019, 12:02:53 PM3/28/19
to TiddlyWiki
I am trying to find out which of 3 separators ( - or / or . ) is being used in a string.

The result of the below gives the title that matches.
1= <$list filter="[[12.34]] +[regexp[(-|/|\.)]]"></$list>

2= <$list filter="[[23-45]] +[regexp[(-|/|\.)]]"></$list>

3= <$list filter="[[34/56]] +[regexp[(-|/|\.)]]"></$list>

Result:
1= 12.34

2= 23-45

3= 34/56

This is the way I am checking to see which separator is returned. I am not satisfied with this cumbersome method, even though it works.
<$list filter="[[12.34]] [[23-45]] [[34/56]]">

<$list filter="[
<currentTiddler>] +[regexp[(\.)]]"><<currentTiddler>> = .</$list>
<$list filter="[
<currentTiddler>] +[regexp[(-)]]"><<currentTiddler>> = -</$list>
<$list filter="[
<currentTiddler>] +[regexp[(/)]]"><<currentTiddler>> = /</$list>
</$list>

Result:
12.34 = .

23-45 = -

34/56 = /

I want the result of my first $list to be the character that matched the regex.
I was wondering if there is a way to construct the regex so that the regexp operator shows exactly what matched, rather than just returning the input title?

Thanks

@TiddlyTweeter

unread,
Mar 28, 2019, 1:13:05 PM3/28/19
to TiddlyWiki
Does the regex filter return anything?


On Thursday, 28 March 2019 17:02:53 UTC+1, S. S. wrote:
I am trying to find out which of 3 separators ( - or / or . ) is being used in a string.

The result of the below gives the title that matches.
1= <$list filter="[[12.34]] +[regexp[(-|/|\.)]]"></$list>

2= <$list filter="[[23-45]] +[regexp[(-|/|\.)]]"></$list>

3= <$list filter="[[34/56]] +[regexp[(-|/|\.)]]"></$list>th

S. S.

unread,
Mar 28, 2019, 7:49:32 PM3/28/19
to TiddlyWiki
Hello Josiah,

Yes, when the input matches the regex filter, it returns the input.

Mark S.

unread,
Mar 29, 2019, 1:03:03 AM3/29/19
to TiddlyWiki
The regexp operator just tests if a title matches. Returning the portion that matches would require something like regexps :


-- Mark

@TiddlyTweeter

unread,
Mar 29, 2019, 1:31:40 PM3/29/19
to tiddl...@googlegroups.com
Ciao S.S.

Mark S. response is correct. The return is whole titles, not the matched string. Nothing gets extracted. Rather, the match is abandoned and only full title strings that include any match to the regex are returned. 

FYI, I think Mark S. is very modest. He has written several JS bits related to expanding regex use in TW that are really helpful

In the past he helped me a lot solve a problem of how to parse Tiddler text for specific strings and action on string match.

Best wishes
Josiah
Reply all
Reply to author
Forward
0 new messages