How to Variable Search and Replace "}"

575 views
Skip to first unread message

Logan Fury

unread,
May 3, 2017, 4:47:27 AM5/3/17
to Tasker
Good Evening,

im trying to strip a closing curly bracket off the end of a variable, and just placing } in search field gives me a bad search pattern error and stops the task.

Do I need to precede the curly bracket with something to make it visible to the action?

Rich D

unread,
May 3, 2017, 4:59:14 AM5/3/17
to Tasker Google Groups Post


Do I need to precede the curly bracket with something to make it visible to the action?

Here is my regex commands sheet.

I would try /}


Regex 

Anchors
^       Start of string or line
\A      Start of string
$       End of string or line
\Z      End of string
\b      Word boundary
\B      Not word boundary
\<      Start of word
\>      End of word

Character Classes
\c      Control character
\s      Whitespace
\S      Not Whitespace
\d      Digit
\D      Not digit
\w      Word
\W      Not Word
\x      Hexadecimal digit
\O      Octal Digit

POSIX Classes
[:upper:]       Uppercase letters [A-Z]
[:lower:]       Lowercase letters [a-z]
[:alpha:]       All letters [A-Za-z]
[:alnum:]       Digits and letters [A-Za-z0-9]
[:digit:]       Digits [0-9]
[:xdigit:]      Hexadecimal digits [0-9a-f]
[:punct:]       Punctuation
[:blank:]       Space and tab [ \t]
[:space:]       Blank characters [ \t\r\n\v\f]
[:cntrl:]       Control characters [\x00-\x1F\x7F]
[:graph:]       Printed characters [\x21-\x7E]
[:print:]       Printed characters and spaces [\x20-\x7E]
[:word:]        Digits, letters and underscore [A-Za-z0-9_]

Pattern Modifiers
//g     Global Match (all occurrences)
//i     Case-insensitive
//m     Multiple line
//s     Treat string as single line
//x     Allow comments and whitespace
//e     Evaluate replacement
//U     Ungreedy pattern

Escape Sequences
\       Escape following character
\Q      Begin literal sequence
\E      End literal sequence

Quantifiers
*       0 or more
+       1 or more
?       0 or 1 (optional)
{3}     Exactly 3
{3,}    3 or more
{2,5}   2, 3, 4 or 5

Groups and Ranges
.       Any character except newline (\n)
(a|b)   a or b
(...)   Group
(?:...) Passive (non-capturing) group
[abc]   Single character (a or b or c)
[^abc]  Single character (not a or b or c)
[a-q]   Single character range (a or b ... or q)
[A-Z]   Single character range (A or B ... or Z)
[0-9]   Single digit from 0 to 9

Assertions
?=      Lookahead assertion
?!      Negative lookahead
?<=     Lookbehind assertion
?!= or ?<!      Negative lookbehind
?>      Once-only Subexpression
?()     Condition [if then]
?()|    Condition [if then else]
?#      Comment

Special Characters
\n      New line
\r      Carriage return
\t      Tab
\v      Vertical tab
\f      Form feed
\ooo    Octal character ooo
\xhh    Hex character hh

String Replacement
$n      n-th non-passive group
$2      "xyz" in /^(abc(xyz))$/
$1      "xyz" in /^(?:abc)(xyz)$/
$`      Before matched string
$'      After matched string
$+      Last matched string
$&      Entire matched string
▶ Show quoted text


Rich D

unread,
May 3, 2017, 5:01:19 AM5/3/17
to Tasker Google Groups Post
oops I meant

\}

Logan Fury

unread,
May 3, 2017, 5:05:18 AM5/3/17
to tas...@googlegroups.com
Good Morning Rich,

The preceeding backslash eliminated the error, but failed to make the curly bracket be replaced by the blank I set. Any ideas on that please?

On Wed, May 3, 2017 at 2:01 AM, Rich D <ricp...@gmail.com> wrote:
oops I meant

\}

--
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/IqCax_wCjqc/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.

Rich D

unread,
May 3, 2017, 5:18:20 AM5/3/17
to Tasker Google Groups Post


The preceeding backslash eliminated the error, but failed to make the curly bracket be replaced by the blank I set. Any ideas on that please?


I am not that good at regex..

perhaps..

.\}

Rich D

unread,
May 3, 2017, 5:21:39 AM5/3/17
to Tasker Google Groups Post


The preceeding backslash eliminated the error,


be sure to use forward slash..

Logan Fury

unread,
May 3, 2017, 5:25:28 AM5/3/17
to tas...@googlegroups.com
forward slash replicated the error. 

.\}

and

\}

caused no error but didnt strip that bracket



On Wed, May 3, 2017 at 2:21 AM, Rich D <ricp...@gmail.com> wrote:


The preceeding backslash eliminated the error,


be sure to use forward slash..

Rich D

unread,
May 3, 2017, 6:45:52 AM5/3/17
to Tasker Google Groups Post


> forward slash replicated the error. 
>

My mistake the backslash is correct .

Always put the issues in the simplest form to debug .

This works for me ...

Regx (337)
A1: Variable Set [ Name:%reg To:sdf{ghk} ggg Recurse Variables:Off Do Maths:Off Append:Off ]
A2: Variable Search Replace [ Variable:%reg Search:\} Ignore Case:Off Multi-Line:Off One Match Only:Off Store Matches In: Replace Matches:On Replace With: ]
A3: Flash [ Text:%reg Long:Off ]

Logan Fury

unread,
May 3, 2017, 7:40:18 AM5/3/17
to tas...@googlegroups.com
Well unfortunately this just isnt working for me. Ive even rebooted the phone but no luck. Ive tried two ways, blank and code for blank, neither work:

Aeris Phase (400)
A1: HTTP Get [ Server:Port:http://api.aerisapi.com/sunmoon/las-vegas,nv?client_id=xxx&client_secret=xxx Path: Attributes: Cookies: User Agent: Timeout:10 Mime Type: Output File: Trust Any Certificate:Off ] 
A2: AutoTools Json Read [ Configuration:Input Format: Json
Simple Mode: true
Json: %HTTPD
Fields: phase
Separator: , Timeout (Seconds):60 ] 
A3: Variable Search Replace [ Variable:%phase Search:\}  Ignore Case:Off Multi-Line:Off One Match Only:Off Store Matches In: Replace Matches:On Replace With: ] 
A4: Flash [ Text:%phase Long:On ] 
A5: Variable Split [ Name:%phase Splitter:, Delete Base:Off ] 
A6: Variable Search Replace [ Variable:%phase1 Search:" Ignore Case:Off Multi-Line:Off One Match Only:Off Store Matches In: Replace Matches:On Replace With: ] 
A7: Variable Split [ Name:%phase1 Splitter:: Delete Base:Off ] 
A8: Flash [ Text:%phase12 Long:On ] 
A9: Variable Set [ Name:%Name To:%phase12 Recurse Variables:Off Do Maths:Off Append:Off ] 
A10: Variable Split [ Name:%phase2 Splitter:: Delete Base:Off ] 
A11: Flash [ Text:%phase22 Long:On ] 
A12: Variable Set [ Name:%Illum To:%phase22 Recurse Variables:Off Do Maths:Off Append:Off ] 
A13: Variable Split [ Name:%phase3 Splitter:: Delete Base:Off ] 
A14: Flash [ Text:%phase32 Long:On ] 
A15: Variable Set [ Name:%Age To:%phase32 Recurse Variables:Off Do Maths:Off Append:Off ] 
A16: Variable Split [ Name:%phase4 Splitter:: Delete Base:Off ] 
A17: Flash [ Text:%phase42 Long:On ] 
A18: Variable Set [ Name:%Angle To:%phase42 Recurse Variables:Off Do Maths:Off Append:Off ] 
A19: Variable Split [ Name:%phase5 Splitter:: Delete Base:Off ] 
A20: Flash [ Text:%phase52 Long:On ] 
A21: Variable Search Replace [ Variable:%phase52 Search:.\}  Ignore Case:Off Multi-Line:Off One Match Only:Off Store Matches In: Replace Matches:On Replace With:\n ] 
A22: Flash [ Text:%phase52 Long:On ]

%phase starts out with opening and closing curly brackets, the opening bracket not being an issue as splitting the value puts it with extraneous text I dont call on.

%phase5 is the last value of import in this, an always changing 5 digit number followed by the closing curly bracket. My A3 looks identical in function to your own so I just cant explain this.

--

Logan Fury

unread,
May 3, 2017, 7:51:09 AM5/3/17
to tas...@googlegroups.com
Woohoo!! Sir I got it!

I added an action after 20, the new action 21 is Variable Search and Replace where I assign %Phase to %phase5, I then changed the Search Replace for curly bracket to search %Phase and its now displaying correctly!

Took me a bit to come to the idea that the fragmenting from Variable Split was causing a difficulty. Heres my working code:

Aeris Phase (400)
A1: HTTP Get [ Server:Port:http://api.aerisapi.com/sunmoon/las-vegas,nv?client_id=xxx&client_secret=xxx Path: Attributes: Cookies: User Agent: Timeout:10 Mime Type: Output File: Trust Any Certificate:Off ] 
A2: AutoTools Json Read [ Configuration:Input Format: Json
Simple Mode: true
Json: %HTTPD
Fields: phase
Separator: , Timeout (Seconds):60 ] 
A3: Flash [ Text:%phase Long:On ] 
A4: Variable Split [ Name:%phase Splitter:, Delete Base:Off ] 
A5: Variable Search Replace [ Variable:%phase1 Search:" Ignore Case:Off Multi-Line:Off One Match Only:Off Store Matches In: Replace Matches:On Replace With: ] 
A6: Variable Split [ Name:%phase1 Splitter:: Delete Base:Off ] 
A7: Flash [ Text:%phase12 Long:On ] 
A8: Variable Set [ Name:%Name To:%phase12 Recurse Variables:Off Do Maths:Off Append:Off ] 
A9: Variable Split [ Name:%phase2 Splitter:: Delete Base:Off ] 
A10: Flash [ Text:%phase22 Long:On ] 
A11: Variable Set [ Name:%Illum To:%phase22 Recurse Variables:Off Do Maths:Off Append:Off ] 
A12: Variable Split [ Name:%phase3 Splitter:: Delete Base:Off ] 
A13: Flash [ Text:%phase32 Long:On ] 
A14: Variable Set [ Name:%Age To:%phase32 Recurse Variables:Off Do Maths:Off Append:Off ] 
A15: Variable Split [ Name:%phase4 Splitter:: Delete Base:Off ] 
A16: Flash [ Text:%phase42 Long:On ] 
A17: Variable Set [ Name:%Angle To:%phase42 Recurse Variables:Off Do Maths:Off Append:Off ] 
A18: Variable Split [ Name:%phase5 Splitter:: Delete Base:Off ] 
A19: [X] Flash [ Text:%phase52 Long:On ] 
A20: Variable Set [ Name:%Phase To:%phase52 Recurse Variables:Off Do Maths:Off Append:Off ] 
A21: Variable Search Replace [ Variable:%Phase Search:.\} Ignore Case:Off Multi-Line:Off One Match Only:Off Store Matches In: Replace Matches:On Replace With: ] 

As always, amazing results from you Rich, thank you very much for your time and the solution!

Have a great day,

Logan

Logan Fury

unread,
May 3, 2017, 7:53:36 AM5/3/17
to tas...@googlegroups.com
A23 Flash %Phase Long: on

is the tail end of that script above that didnt make it to the paste and confirmed success.

sorry about that!
Reply all
Reply to author
Forward
0 new messages