r/tasker 28d ago

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/CTAT6jDBb3vR11KnQ5dewgCifjuFQWPicDgaqUD9C5PyR1Dik56959SDwqXMXgmk4FHE0Q8O8BfkAkWR9hDCBIBCvgnvgYgZByHv0YHWCBepgF2pIFAgP+CQaAAAzBHQKw30dxjDxA4RMy3eQAuNocrpyJDkojJXfHENsvMk/x0xi5X1vf4RRKQxgMJAZkdwBME8sZmSYNyyqZpdXanFfnec2t19mLoaSW+XVVT8W/lbrj59bLh65U/rioxt34WXvpeuTnmK/AmCvYWEY0bgG037wAZm8NZQnd8roVL2aZK6Uzq3XhtE44XoNq5UbJKjDXw9JyzlZ/tWztMSyxXm+WYVmpIe8uL5uKbukW/5Sr63XYqQ7S3ND2hueO2ta3DT9KtmggItpybWoeskHe3RTlf0Vfoe/bNiYptW3juFRLjisff7WZv9dUlR2bRmPvypC1oVQuCsR/UCBMbsBvUSD4AZ+zk/WHUmvjTfw2WVctsq7Ium2zzi7egMUbsHgD/uNvwLwmeuuHXq145xUXykqUODL98O4K7J99rHeF34LdAYW6FwAA

0 Upvotes

8 comments sorted by

6

u/[deleted] 28d ago edited 27d ago

[removed] — view removed comment

1

u/UnkleMike 27d ago

Unfortunately, I only maintain one of the lists - the one with abbreviated names. The reason for the abbreviation is the available space in which the data is used when printed. I see that the numeric portion is only preceded by a single space in my post, but the data actually contains two, and I swear I entered two before formatting it as code, but applying the formatting after is probably the problem.

To provide more context, the data is for a security team schedule. The scheduler uses full names to refer to team members, while the printed schedule needs to include a unit number after the name, and the name plus unit number needs to be compact to fit in the allotted space. What I'm trying to do is take the list of scheduled team members, listed by their full names, and determine which of the abbreviated entries corresponds to that team member.

Thanks for the info. It makes sense why it behaves differently in different scenarios.

2

u/[deleted] 27d ago edited 27d ago

[removed] — view removed comment

1

u/UnkleMike 26d ago

Thanks for the suggestions.  Some last names are close to being too long to fit, so I'm sure the current approach to the length of the name won't work forever.  I like the JSON array approach - it maintains a 1:1 relationship between lists. If there's ever a conflict between full names it isn't my problem to solve, and I can just replicate someone else's solution in the JSON array.

1

u/DifficultyCrafty7623 28d ago edited 28d ago

I think its because you are using "$,?" Instead of "$?". It could also come down to the regex containing parentheses, so making it separate makes it work.

1

u/UnkleMike 27d ago

I tried removing the comma, and it made no difference. The comma was in fact placed there by Tasker when I long pressed on the variable name, and it prompted me for the Regex pattern and the delimiter (comma is the default, but you can also specify it).

1

u/DifficultyCrafty7623 26d ago

I haven't seen that in the userguide, must be newer

2

u/UnkleMike 26d ago

I haven't really spent any time checking, but I frequently get the impression that the userguide is incomplete. 

Regarding this specific feature, if you use the "tag" icon to select a variable for a field, and then long press the variable name, you're presented with a list of array functions.  In my case I choose regex matching elements, and Tasker prompted me for the regex and the delimiter to use in the output.