How to write a safe catch-all RegExp

In my Chili recipes I use the regexp /(?:.|n)/ when I want to mean each and every char. It cannot be just a dot, because a dot doesn’t match n (AKA new line AKA line feed AKA 0x0A). Due to the fact that I erase from the input any r (AKA carriage return AKA 0x0D) before trying a match, the regexp I use is almost safe, in fact I do not consider u2028 nor u2029, two additional (unicode) new line chars that a dot doesn’t match.

In short, and in general, a safe catch-all regexp is /(?:w|W)/ which means any word char or any non-word char.

So, if you are concerned with these unicode details and can’t wait till the next release of Chili, I advise you to search (?:.|n) and replace any occurrence with (?:w|W).

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.