Validator.matchesRegex in Mule blows up with basic pattern
<p>I am receiving a date in message as a string. the following regular expression will confirm it is in at least the format I know I can handle:</p>

<pre><code>^[0-9]{4}\-(0?[1-9]|1[012])\-(0?[1-9]|[12][0-9]|3[01])$
</code></pre>

<p>but when I provide this regex to the validator.matchesRegex method in the Mule Expression language like so:</p>

<pre><code>&lt;when expression="#[validator.matchesRegex(payload.DateOfBirth,'^[0-9]{4}\-(0?[1-9]|1[012])\-(0?[1-9]|[12][0-9]|3[01])$') == false]"&gt;
    &lt;set-variable variableName="validation_message" value="{&amp;quot;error&amp;quot;: &amp;quot;Invalid DateOfBirth&amp;quot;}" doc:name="invalid DateOfBirth"/&gt;
&lt;/when&gt;
</code></pre>

<p>I receive the following error:</p>

<pre><code>org.mule.api.MessagingException: [Error: illegal escape sequence: -]
[Near : {... eOfBirth,'^[0-9]{4}\-(0?[1-9]|1[012])\-(0?[1-9]|[1 ....}]
                                                                  ^
[Line: 1, Column: 55] (org.mule.api.expression.InvalidExpressionException). Message payload is of type: HashMap
</code></pre>

<p><strong>update</strong>
I've tried two new alterations:</p>

<ol>
<li><p>doubling up my curly brackets like so:</p>

<p>^[0-9]{{4}}-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])$</p></li>
</ol>

<p>but I get the same error but a few characters off:</p>

<pre><code>[Error: illegal escape sequence: -]
[Near : {... fBirth,'^[0-9]{{4}}\-(0?[1-9]|1[012])\-(0?[1-9]|[1 ....}]
                                                                    ^
[Line: 1, Column: 57] (org.mule.api.expression.InvalidExpressionException). Message payload is of type: HashMap
</code></pre>

<ol start="2">
<li><p>unescaping the dashes between the numbers</p>

<p>'^[0-9]{{4}}-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])$</p></li>
</ol>

<p>but I get the following error:</p>

<pre><code>org.mule.api.MessagingException: Execution of the expression "validator.matchesRegex(payload.DateOfBirth,'^[0-9]{{4}}-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])$') == false" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: HashMap
</code></pre>

<ol start="3">
<li><p>I have changed the pattern to not use the escape backslash to only accept the dash:</p>

<p>^[0-9]{4}.(0?[1-9]|1[012]).(0?[1-9]|[12][0-9]|3[01])$
I have replaced '-' with '.' which is not really what I want, but it at least validates the number portions. I have confirmed this works. it just allows invalid values such as '2016!02_23' when it really should only allow '2016-02-23'</p></li>
</ol>

<p><strong>TL;DR:</strong> there is a bug with regular expressions within MEL when you are trying to escape the dash character? </p>