Seeking example of "retrieving regex groups" in Tasker

444 views
Skip to first unread message

David Berlind

unread,
Sep 13, 2016, 3:39:20 PM9/13/16
to Tasker
Hey all, 

I was reading this bit in the Tasker docs about retrieving Regex groups and was wondering if anybody could show me a working example or walk me through it.  I see that I have to call "Perform Task" but am a little lost as to where to call it from in my workflow, what and why to name it (it requires a name), and am generally just hoping for clear example that ends with the global arrays being populated as described.

The reason I need it is Tasker relies on JS regex which doesn't support lookback reference. So, I want to use regex groups to extract text from between quotes... for example, if I start with this:

"Extract this Text"

I want to end with this:

Extract This Text

Tasker's search and replace does the trick... but I'm more interested in this "easy" use case to show me how to retrieve the groups.

Thanks in advance to anyone who can help.

Robert Ryan

unread,
Sep 13, 2016, 4:21:56 PM9/13/16
to tas...@googlegroups.com

When I wrote this task 18 months ago there was no better way to get captured groups. Now, however,  the Regex action in the AutoTools plug-in is a much better  option.

That being said, here is how to use the old way.

        Test (7)
       
    A1: Variable Set
        Name:%string
        To:"Extract this text"
        Do Maths:Off
        Append:Off 
       
    A2: Perform Task
        Name:Regex
        Priority:%priority+1
        Parameter 1 (%par1):%string
        Parameter 2 (%par2):"([^"]+)"
        Stop:Off 
       
    A3: Flash
        Text:%rxGroup(1)
        Long:Off 

David Berlind

unread,
Sep 14, 2016, 11:25:15 AM9/14/16
to tas...@googlegroups.com
thanks Robert...in the second action, where does "Regex" (the name) come from?

--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/T4_HZzIN2h8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/d/optout.

Robert Ryan

unread,
Sep 14, 2016, 11:58:54 AM9/14/16
to tas...@googlegroups.com

Regex.tsk.xml is the name of the file that you should have downloaded from the documentation page you mentioned in your first post. When you import that into Tasker it will create a new task called Regex. That is the task I call in the Perform Task action.

> Tasker relies on JS regex which doesn't support lookback reference

If you mean a zero width look behind reference that looks like this:

(?<=a)

Then Tasker does support this. I use it quite often in fact.

David Berlind

unread,
Sep 14, 2016, 12:23:30 PM9/14/16
to tas...@googlegroups.com
well, no wonder I was confused. I don't see  any reference to a download on that page.  Am I blind?

on the backreference question, my searching (for some reason, I can't find it again),.. revealed some mention of Javascript not supporting backreferencing for the purpose of capturing groups. I'm a novice when it comes to Regex... so I don't know the accuracy of that. But then, I read somewhere that Tasker's Search/Replace (to the extent that it supports regular expressions) relies on the Javascript engine.

--

Robert Ryan

unread,
Sep 14, 2016, 1:27:45 PM9/14/16
to tas...@googlegroups.com

At the bottom of the page you referenced, there is a link. I circled it in red in the attachment. Click that to get to the file downloads.

Sorry for the confusion, I thought you had already done that.

IMG_20160914_112303.jpg

Robert Ryan

unread,
Sep 14, 2016, 1:32:36 PM9/14/16
to tas...@googlegroups.com

On September 14, 2016 10:23:24 AM David Berlind <da...@berlind.org> wrote:

> I read
> somewhere that Tasker's Search/Replace (to the extent that it supports
> regular expressions) relies on the Javascript engine.


Actually Tasker uses Java methods, not Javascript.

David Berlind

unread,
Sep 14, 2016, 2:14:42 PM9/14/16
to tas...@googlegroups.com
thanks. darn web. Can't believe everything you read.  ;)

I need to work on my regex yellow belt anyway (about the only book I have kept forever is O'Reilly's Mastering Regular Expressions. Of course, that was acquired long before the Web was packed with regex examples and interactive tools.

--
Reply all
Reply to author
Forward
0 new messages