rivescript-python
rivescript-python copied to clipboard
Space toleration outside optional bracket
The optional brackets accept multiple spaces between optional and main text (like between hello and (you|me) in 1st trigger). But if it happens that space is missing (likely an unnoticed typo), the matching for 2nd trigger will be how areyou and how areu, but NOT how are you.
+ hello (you|me)
- hi
+ how are(you|u)
- i am fine
@kirsle What do you think about space tolerance for optionals?
This form should probably still work:
+ how are(you|u)
- i am fine
In that example it'd probably be a typo, but I could see users deliberately not including a space because they want to match multiple prefixes or suffixes on a word and don't want to have to repeat the entire word multiple times, like + fox(es|s) (it's too early in the morning to think of a better example :wink: ).
However, consolidating 2+ spaces in the trigger down to 1 space would sound reasonable. I couldn't imagine someone relying on the user needing to type 2+ spaces between words to match a trigger.
The regexp could be like re.sub(r'\)\s+', ') ', trigger) for every combination of \s+ touching the edge of a parenthesis symbol.