How to search and replace with regex?

79 views
Skip to first unread message

Noel Yap

unread,
Aug 3, 2018, 5:31:20 PM8/3/18
to Tasker
I'm trying to turn `one=1,two=2` to `${one}=:=1,${two}=:=2`. That would normally be done in two steps. Using `perl` notation:
s/(\b\w+\b)/${\1}/g
s/=/=:=/g

I haven't been able to figure out how to get back references (ie `\1`) in Tasker nor have I found a way to use AutoTools to perform search and replace. Any help would be appreciated.

Thanks,
Noel

Robert Ryan

unread,
Aug 3, 2018, 7:54:11 PM8/3/18
to tas...@googlegroups.com
This should work. Make sure that there are no spaces in the search string. See attached screenshot. 

        Test
        
    A1: Variable Set 
        Name: %string 
        To: ${one}=:=1,${two}=:=2 
        Recurse Variables: Off 
        Do Maths: Off 
        Append: Off 
        
    A2: Variable Search Replace 
        Variable: %string 
        Search: \$\{([^}]+)\}=:=(\d+) 
        Ignore Case: Off 
        Multi-Line: Off 
        One Match Only: Off 
        Replace Matches: On 
        Replace With: $1=$2 
        
    A3: Flash 
        Text: %string 
        Long: On 


--
You received this message because you are subscribed to the Google Groups "Tasker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tasker+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/d/optout.

Screenshot_20180803-175011_Tasker.jpg

Robert Ryan

unread,
Aug 3, 2018, 8:10:55 PM8/3/18
to tas...@googlegroups.com
Oops, I got that backward didn't I? Try this instead, see attached. 

        Test
        
    A1: Variable Set 
        Name: %string 
        To: one=1,two=2 
        Recurse Variables: Off 
        Do Maths: Off 
        Append: Off 
        
    A2: Variable Search Replace 
        Variable: %string 
        Search: (?<=^|,)([^=]+)=(\d+) 
        Ignore Case: Off 
        Multi-Line: Off 
        One Match Only: Off 
        Replace Matches: On 
        Replace With: \${$1}=:=$2 
        
    A3: Flash 
        Text: %string 
        Long: On 


Screenshot_20180803-180714_Tasker.jpg

Noel Yap

unread,
Aug 5, 2018, 8:00:06 PM8/5/18
to tas...@googlegroups.com
Ah, right, `$1`, not `\1`. Thanks.
Reply all
Reply to author
Forward
0 new messages