Hi there,
I have an automation that I’m working on. It involves needing a regex expression to be able to filter calendar events. The logic should be as follows:
- If event begins with the letter T, return false. End.
- If there are 3 or 4 consecutive digits, return True.
Some examples:
“T7575” = False (begins with T)
“ABC 867 ZXY” = True (867)
“Pickup” = False
“Some words (55:76)” = False (only 2 consecutive numbers)
“YGF AB658 YHJ” = True (658)
“YGF 6658 YHJ” = True (6658)
Basically, as long as the event doesn’t begin with T and there are 3 or 4 numbers in a row anywhere, it should be true.
Other notes:
- Sometimes there will be letters next to the numbers, sometimes not
- Will have to be able to work with spaces before/after the letters (and ignore them). Sometimes spaces will be there, sometimes not.
Here is what I have so far:
value_template: >-
{{ trigger.calendar_event.summary |
regex_match('^(?!T).*\\b\\d{3,4}\\b.*') }}
So far, entries such as “ABC 123 XYZ” have been returning true, as it should. However it appears to fail when there are letters immediately next to the numbers. For example: “ABC DE875 XZY” should return true, but it’s returning false right now.
Any help would be greatly appreciated! Thanks in advance.