I’m trying to configure a CalDav item to only match a specific RegEx. I confirmed that the actual regex is correct. The doc says:
filter-name:'\<regular expression\>'
How should I enter my Regular Expression?
Just entering filter-name:‘Regular Expression here’ seems to match everything. Entering like filter-name=’\Regular Expression here’ gives an error upon loading.
How should I use regex in the caldav configuration?
After you sure, because REGEX works differently in OH from standard. Your expression must match the full string, even if it’s multiple lines. Only the first group gets returned.
Events in my calendar are not multiline and I think the first group has the value.
But I will try to be more specific, maybe you can help.
The regex I have:
^Szállás|^szállás|Hotel|hotel
So I want to filter the events which start with ‘szállás’ (or with an uppercase - I know that there are flags also for this, but I don’t know if it works in OH or not) or has the word ‘Hotel’ in the event name.
It gives a ‘Full match’ for me on a regex tester like this:
Or maybe I just need to add braces for this regex like this:
(^Szállás|^szállás|Hotel|hotel)
This is what I haven’t tried yet. This way it also returns the 1st Group in every Regex tester.
Like I said, the regular expression must match the full string. That regular expression will only match one word. I doubt your calendar entry is just one word so you need to have the regular expression match everything after that first word too.
@rkrisi, did you ever get this working? I just had a go with some Items and figured out a few… nuances of this binding. The binding is using regex to extract the regex for the filter-name. When you use anything other than what is in the allowed character set, the matching stops. Your filter expression cannot contain anything other than A-Z, a-z, ., *, +, -, |, and spaces. You are using special characters, which will stop the matching. Character sets will also stop the matching due to the [. If the matching stops before the end, nothing will be found. However, if the matching stops at the very beginning, like when ^ is used, then there is effectively no filter and everything is returned. Hopefully some of this makes sense! The documentation definitely needs an update.
I was hoping you’d take an interest in this one . The binding uses…
private static final String REGEX_FILTER_NAME = "filter-name:'?([A-Za-z\\.\\*\\+\\- \\|]+)'?";
… as its regex, which excludes everything else. As a minimum, I’d add [, ], ?, ^, :, 0-9, and $. I could do a PR, but time is tight. It’s simple though…
private static final String REGEX_FILTER_NAME = "filter-name:'?([!@%&#:0-9A-Za-z\\.\\*\\+\\- \\|\\?\\[\\]\\^\\$]+)'?";
Although, I wonder why characters are being whitelisted instead of blacklisted. Or, why not allow everything?
private static final String REGEX_FILTER_NAME = "filter-name:'(.*)'";