Tasker Variable Search/Replace and Regex

5,305 views
Skip to first unread message

Andy Carr

unread,
Mar 11, 2015, 5:26:31 PM3/11/15
to tas...@googlegroups.com
Wondered if anybody could help, been trying to get my head around regex for the first time and Tasker's Variable Search Replace action.  In short I'm struggling extracting a string from within a defined variable. 

In my variable %VarTest I have the following string http://maps.google.com/maps?q=N51.307278,W000.143415 。

I'd like to initially extract just the co-ordinate portions of the string excluding the last special character e.g. N51.307278,W000.143415

and then split the variable at the "," {comma} into separate %VarLat and %VarLong variables.

So far I'm using the regular expression maps\?q\=(.*)\s and the resulting group passed out equals maps?q=N51.307278,W000.143415

So question is can I tweak the regex to only grab the string after the match? I've read bits about lookforward lookbehind but can't get my head around it and realise I could run a split on the initial expression before splitting on the comma but wanted to try to make this efficient if possible.

So any help would be appreciated and even better if you can solve this please explain what is going on with the expression so I can learn a bit.

Thanks in advance

Richard Wallace

unread,
Mar 11, 2015, 6:16:26 PM3/11/15
to tas...@googlegroups.com
This should do it...
Search And Replace (239)
A1: Variable Set [ Name:%var To:http://maps.google.com/maps?q=N51.307278,W000.143415 Do Maths:Off Append:Off ]
A2: Variable Search Replace [ Variable:%var Search:(?<==).* Ignore Case:Off Multi-Line:Off One Match Only:Off Store Matches In:%match Replace Matches:Off Replace With: ]
A3: Variable Split [ Name:%match1 Splitter:, Delete Base:Off ]
A4: Flash [ Text:%match1 Long:Off ]
A5: Variable Set [ Name:%lat To:%match11 Do Maths:Off Append:Off ]
A6: Variable Set [ Name:%lon To:%match12 Do Maths:Off Append:Off ]
A7: Flash [ Text:%lat
%lon Long:Off ]

Andy Carr

unread,
Mar 11, 2015, 7:36:04 PM3/11/15
to tas...@googlegroups.com
Thanks Richard, works a treat....

The regex is almost there, still getting the leading = {equals} character in the resulting string variable.  So have used Variable Section to get rid of character 1 in %Match1 before performing the Spilt using the comma.

Cheers.

Richard Wallace

unread,
Mar 12, 2015, 6:14:07 AM3/12/15
to tas...@googlegroups.com
No problem,
The task i posted for me works OK for me with the resulting varibles as you want?
Reply all
Reply to author
Forward
0 new messages