Regular Expression miskatch

67 views
Skip to first unread message

Larry Schweyer

unread,
Jul 23, 2025, 1:52:06 PMJul 23
to Tasker
I use regular expressions quite a bit. I've just noticed one that doesn't appear to be prosscess the way I thought it should. I have this regular expression in an IF statement: IF %antitle !~R(?I).*events*

When the app runs the %antext value is "Test event". The IF statement doesn't run because of the "event". Does this match with *events*?

I've had this happen before. Am I doing this wrong? I only want the IF to run if the string doesn't contain "events" not "event"

Hope this makes sense

Gilles P

unread,
Jul 24, 2025, 7:24:41 AMJul 24
to Tasker
the "ignore" case modifier is "(?i)"  not  "(?I)" (lower case)

RSF

unread,
Jul 25, 2025, 1:40:05 AMJul 25
to Tasker
If you want "Test event" to be matched, but not "Test events" (I.e., the word event has to appear but not the word events), the regular expression should be:
    (?i)event($|[^s])
The part in parentheses says "following the string "event", there has to be either the end of the overall string, or anything other than an s". And you'd want the IF action to be ~R, not !~R.

If you want to exclude any string containing "events" (, you could use a "Not Matches" IF statement (not a regular expression) with
   *events*
as the string. If you wanted to use a regular expression, the !~R regular expressions should be just 
   (?I)events 
No need for asterisks...

(Also: Gilles is correct about the case-insensitive switch. The "i" has to be lower-case)

Larry Schweyer

unread,
Jul 25, 2025, 7:01:27 AMJul 25
to tas...@googlegroups.com
Sorry, yes I know, its a typo. I've used this expression many times. It is lower case in my task.

I've had this happen several times when the data is as I mention like this: "events" "event". Can someone at your end just try it?

I have the latest version of Tasker. 

Thanks.

--
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/O56RDG0x7gU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/tasker/a5c39495-a0b5-4d71-8601-756023bcf852n%40googlegroups.com.
Larry

RSF

unread,
Jul 25, 2025, 10:47:11 AMJul 25
to Tasker
I may not understand the scenario. Is it that you want "event" to match but not "events". If so, from before:

If you want "Test event" to be matched, but not "Test events" (I.e., the word event has to appear but not the word events), the regular expression should be:
    (?i)event($|[^s])

See this example on Regex101.com

Larry Schweyer

unread,
Jul 28, 2025, 7:42:13 AMJul 28
to tas...@googlegroups.com
Thanks for that week try it. I did mention previously that in my task it was lower case i. I mistyped that in my post.

But I'm still wondering. I'm looking for 'events' not 'event'. Why does *event* match with *events*

--
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/O56RDG0x7gU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.

Larry Schweyer

unread,
Jul 28, 2025, 7:42:15 AMJul 28
to tas...@googlegroups.com
Ok. Assume just one word. I want to check if the string contains "event". The string contains '... event...'. The regular expression is trying to match *events* and says it matches event which doesn't sound right to me.

When run the IF runs because it decided "events" matches "event" which doesn't sound right to me.

Appreciate your help here. I must be misunderstanding it. Maybe you could try it and see what I mean?

Thanks

RSF

unread,
Jul 28, 2025, 9:55:51 AMJul 28
to Tasker
The asterisk in a regular expression means "match the preceding character/expression zero or more times". Thus events* will match event, events, and eventssssss.

If you want to match events but not events, just use a regular expression of events

You may be mixing:
  • Tasker's more basic "pattern matching" ability (where an asterisk means "some number of characters", and where *events* means "find the string events anywhere in the overall string, with possibly some characters before and after), and
  • Regular expression matching (where an asterisk means "repeat the prior character/expression zero or more times).
I'd thought you wanted to match event but not events, vs. the other way around; I misunderstood. The regular expression I provided would work for that scenario.


Larry Schweyer

unread,
Jul 28, 2025, 10:01:43 AMJul 28
to tas...@googlegroups.com
Ok thanks. Got tonl think this over. Still don't get why events matches event. I would have thought all the letters in events would have match but event has no s.

Larry

RSF

unread,
Jul 28, 2025, 10:25:07 AMJul 28
to Tasker
With regular expressions:
  • events* matches the string event (because the asterisk says the previous "s" can be matched zero, one, or multiple times; it'll match event, events, and eventsss)
  • events won't match the string event (because there's no asterisk modifying that "s", so the "s" has to appear in the string; it'll match events and eventsss but not event)
regex101.com is a great free resource for learning about, and testing, regular expressions.

Larry Schweyer

unread,
Jul 28, 2025, 10:28:35 AMJul 28
to tas...@googlegroups.com
Ok thanks. Got to think that over for a bit. I used expressions years ago at IBM. Guess things have improved?

Larry

Gilles Pion

unread,
Jul 28, 2025, 10:33:02 AMJul 28
to tas...@googlegroups.com
There are many online sites to test and experiment regexps easily.

--
Gilles Pion

Larry Schweyer

unread,
Jul 28, 2025, 10:36:57 AMJul 28
to tas...@googlegroups.com
Thanks will do. Guess I'm a bit behind.

Larry

Larry Schweyer

unread,
Jul 28, 2025, 10:39:41 AMJul 28
to tas...@googlegroups.com
Appreciate your patience

Larry

On Mon, Jul 28, 2025, 10:33 Gilles Pion <gille...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages