6

Allow variable to be set to result of search and replace

It would be useful to perform a search and replace to a variable then place the result into another variable. Also doable, but more complicated in both implementation and use, is to allow lookahead regexes.

5 replies

RR

The Variable Search Replace action already has this capability.

NY

I'm seeing an option "Store Matches In" but not an option to store the result of the search and replace. Maybe I'm misunderstanding what that option actually does?

RR

The replacement is done in the original variable. For instance, this replaces the word dog with the word cat.

        Test (68)
        
    A1: Variable Set 
        Name: %string 
        To: There is a dog in the house 
        Recurse Variables: Off 
        Do Maths: Off 
        Append: Off 
        
    A2: Variable Search Replace 
        Variable: %string 
        Search: dog 
        Ignore Case: Off 
        Multi-Line: Off 
        One Match Only: Off 
        Replace Matches: On 
        Replace With: cat 
        
    A3: Flash 
        Text: %string 
        Long: On 

TP

I think I see what you're saying. Rather than doing the Search/Replace on the input variable itself - you'd like the action to output a totally separate variable, leaving the original value un-changed?

That probably wouldn't be too hard to add to Tasker. However at the moment, you can do it by making a copy of the main variable before you do the Search/Replace, and then specifying the copy as the input. 

NY

Yes, I was expecting that if the result is to be stored in another variable, the original variable isn't modified and the new variable actually has the result of the search-and-replace.