Behat/Behat — pull request #518 by stof (2014-04-27 14:09:59+00:00)
Title: Improved the error reporting for invalid regexes in step definitions

If the pattern looks like a regex but is not valid, an exception is now thrown rather than letting it be considered as a turnip pattern.
The reasoning is that it is very easy to make a mistake in the regex (forgetting a closing parenthesis for instance, like in the scenario), especially when the regex is a bit complex. And debugging it is currently a huge pain.

"Looks like a regex" means that it starts with a regex delimiter, and ends with the corresponding delimiter optionally followed by some regex modifiers.
The list of supported delimiters is restricted compared to what PHP supports (i.e. any non-alphanumeric, non-backslash, non-whitespace char) to be sure we don't match something expected to be a turnip pattern by mistake by considering a really weird delimiter. We support `` ` ``, ``/``, ``~``, ``#`` or ``{}``. This is technically a small BC break (if someone wrote a regex using another delimiter in 3.0). There is a way to preserve BC: support any valid regex or anything looking like a regex with these delimiters. This means that you would still get error reporting for invalid regexes using these supported delimiters, but you can still write regexes using other patterns as long as you don't make mistakes in them (like currently). What do you think @everzet ?