Javascript regex quirk


When I’ve written the SMOG analyzer javascript I found a quirk of javascript and this recent post inspired me to share it:

The javascript regex specification doesn’t have the s modifier. This is necessary when you want to match multiple lines with a construct like .*. The suggested workaround I found was to specify the [sS] character class which means “any space or non-space character”.

BTW, I find that the multi-line / single-line name for the /m and /s modifiers is somewhat a misnomer, since it leads you to believe that you can’t use them together (how can something be a single line and multiple lines the same time?), however this is not true, since they refer to different elements (^ and $ versus .), which means that you can use and sometimes you need to use them.

,

Leave a Reply

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