Reputation: 79
I am trying to make a regex pattern for a Watson Assistant Entity that detects dates similar to those in bold:
I have used the following expression to do it:
( \b(?:3[01]|[12][0-9]|0?[1-9])([\-/.])(1[1-2]|0?[1-9])(?![\-/.])\b )
This expression works well, the problem is that the pattern comparison engine that is used in Watson, has syntax limitations.
Entity patterns cannot contain:
At this point, I cannot use (?![-/.]) to avoid dates like '25/02/2020'.
How can I do it?
Thanks in advance,
Upvotes: 0
Views: 270
Reputation: 9357
First this way may only work in the US (I tried it with a different $timezone
but didn't work, but it could be a "try it out" issue).
Switch on @sys-date
. If you user says "date 02/18 of" it will pick up 02/18 as 2020-02-18. You can then work with the date easier.
The other approach is to create a cloud function to do the complex regex for you and hand it back to Watson Assistant.
Upvotes: 1
Reputation: 2227
I do not have Watson Assistant Entity for testing, but this should work:
\s\d?\/\d?\s
or
\s\d{1,2)\/\d{1,2}\s
or
\s(\d|\d\d)\/(\d|\d\d)\s
where \s
is white space, and \d
is any digit
The site does not provide a proper manual with the abilities of the regex engine (at least, I did not find it). So I provided work-arounds for the said limitations.
It does not validate that the dates are realistic, but since 30/2
(February 30) is a valid match, there should be no problem.
Upvotes: 0
Reputation: 5308
You may try with this:
[ ]((?:3[01]|[12][0-9]|0?[1-9])([\-/.])(1[1-2]|0?[1-9]))(?:$|[^\d\-/.])
I'm assuming you need the different capturing groups you used on your question. If that's not the case, you may remove them or replace them with non-capturing groups (?:)
I'm also assuming you don't need to capture the space on the capturing group, so I put it aside.
So the basic idea is that before your expression you may want to find either end of string/line $
or some character that is not number, -
, /
or .
.
Upvotes: 1