Regex pattern matching inconsistency
While working on a small task that uses two arrays, where for an element in array %names_array I need to find the corresponding elements in another array, I ran into what I believe is an inconsistency on how Tasker handles variable substitution within regular expressions.
As a simplified example, I have %names_array with two elements:
Do.Maguire 35
Da.Maguire 43
representing two people with the last name Maguire, each preceded with enough information to make the non-numeric part of each element unique (imagine the names are Donald Maguire and David Maguire). In use, the array contains about 50 names, but this is just an example.
I need to find all elements that may correspond to the full name Donald Maguire. To do this I'm extracting the last name from the full name, setting the variable %last_name to Maguire. I then use Array Set to populate %matches_array with matching elements from %names_array:
A7: Array Set [
Variable Array: %matches_array
Values: %names_array($,?~R^(\p{L}+\.)?%last_name\s{2}\d{2}$)
Splitter: , ]
Unfortunately, what I end up with in %matches_array is two elements:
%names_array($
?~R^(\p{L}+\.)?%last_name\s{2}\d{2}$)
But if I instead set variable %regex to the desired pattern first, then reference that variable in the Array Set action:
A3: Variable Set [
Name: %regex
To: ^(\p{L}+\.)?\%last_name\s{2}\d{2}$
Structure Output (JSON, etc): On ]
A4: Array Set [
Variable Array: %matches_array
Values: %names_array($,?~R%regex)
Splitter: , ]
I get these two elements in %matches_array:
Do.Maguire 35
Da.Maguire 43
When using the Simple Match/Regex action, I get the opposite results - defining the Regex in a separate variable first doesn't work, and using the Regex directly in the action does work.
This seems inconsistent to me. Below is a task description and and a task URL that demonstrate this. Am I missing something?
Task: Regex Test
A1: Array Set [
Variable Array: %names_array
Values: Do.Maguire 35,Da.Maguire 43
Splitter: , ]
A2: Variable Set [
Name: %last_name
To: Maguire
Structure Output (JSON, etc): On ]
A3: Variable Set [
Name: %regex
To: ^(\p{L}+\.)?\%last_name\s{2}\d{2}$
Structure Output (JSON, etc): On ]
A4: Array Set [
Variable Array: %matches_array
Values: %names_array($,?~R%regex)
Splitter: , ]
A5: Flash [
Text: %matches_array()
Tasker Layout: On
Background Colour: #FFD03636
Timeout: 10000
Dismiss On Click: On
Position: Top ]
A6: Array Clear [
Variable Array: %matches_array ]
A7: Array Set [
Variable Array: %matches_array
Values: %names_array($,?~R^(\p{L}+\.)?%last_name\s{2}\d{2}$)
Splitter: , ]
A8: Flash [
Text: %matches_array()
Tasker Layout: On
Background Colour: #FFD03636
Timeout: 10000
Dismiss On Click: On
Position: Top ]
A9: Simple Match/Regex [
Type: Regex
Text: %names_array(1)
Regex: %regex ]
A10: Flash [
Text: %mt_match
Tasker Layout: On
Background Colour: #FFD03636
Timeout: 10000
Dismiss On Click: On
Position: Top ]
A11: Variable Clear [
Name: %mt_match ]
A12: Simple Match/Regex [
Type: Regex
Text: %names_array(1)
Regex: ^(\p{L}+\.)?%last_name\s{2}\d{2}$ ]
A13: Flash [
Text: %mt_match
Tasker Layout: On
Background Colour: #FFD03636
Timeout: 10000
Dismiss On Click: On
Position: Top ]
Task URL: Check out my Tasker Task "Regex Test!"
taskertask://H4sIAAAAAAAA/+1Y3W/aMBB/bv4KK+sq0Gi+E4IaMtHRTpXoHijqy9CQS1yaDRKUGLqq6v722TGEUEz4qjRtywvYd+fz785353OcDox/oKgJMQRxVBdF4E39uqiKAE/roiVVJev0DmEousKRQ2UTKUwGlkppR07fgxi5atW2TE1TFDLQHZkRKRulbMs2bEtRNduRUcr2PddSHZn80VkwQm4bDdBP0EExdmQ6p/Rx5LuqojgyHVBCo4/9MEiwwD5WRDBFdbGaACKIQg+5umkQGHSU0G5wxKSjwUxaF933ARyhuAejCD45MhFZkVVT2WYoXcPBxI8QALpZacLF1ND5i7V0cSUVcGQGnWOFyrHCNKqbrRjCGPeoKZtsmCHOiF0FOIsWDuuiIsorPD2HZ+TwzBlP5/CsGU9lvDzH8M7XNGqbPTPCvRHE/Qe+xWoO8h28kYecd6Z6zcoiP58E3hAtwCfUI+cWDuOESLaa0Uh+ICx5fjAY+nH/QYKBF4W+J+EkhaX2RevitvGl07tttK8a562LG/dkiM+I5WRFg8Y4y/CTAT6jDBb3vR11KnQ5dewgCifjuFQWPicDgaqUD9C5PyR1Dik56959SDwqXMXgmk4FHE0Q8O8BfkAkWR9hDCBIB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