I tried the following on text event:
on $*:TEXT:m/(snake| $+ $replace($me,[,\[,],\]))/:#:echo -s TEST COMPLETE
It didn't work somehow, but somehow
//echo -ag $regex($me,snake| $+ $replace($me,[,\],[,\[))
would return 1
Is there a workaround? I also tried it with
on *:TEXT:$($regex($me,snake| $+ $replace($me,[,\],[,\[)))
and that didn't work either
on *:TEXT:*:#:{
;make regex
var %r = /(snake| $+ $replace($me,[,\[,],\]) $+ )/
;if regex fails, stop here
if (!$regex(,$1-,%r)) return
;rest of code goes here
}
-genius_at_work
The reason I had a specific event is so I wouldn't have an event trigger when there's nothing to match, so it's just wasting cpu.
I doubt you would be able to detect the greater cpu cycles used by the suggested code, when used in realistic testing.
I don't know if $identifiers are allowed in event regex matches.. this might work:
on $*:TEXT:m/(snake| $+ $replace($me,[,\[,],\]) $+ )/:#:echo -s TEST COMPLETE
You may run into problems if there are other special regex characters in your $me, such as (){}\.*+?$^ . If $ids are allowed, you could make a custom alias to escape all non-alnum chars. Something like this
alias escape {
var %s, %r = $regsub(,$$1-,/[^ \w]/g,\\\1,%s)
return %s
}
(untested)
-genius_at_work
You need to use $() to let identifiers evaluate in the matchtext part. This means putting the entire expression within $(), not just the identifier. There's no need for the m either, since you're using the default regex delimiters / /.