Dynamic routing via plugin with special characters After learning how to use dynamic routing in MyPluginPlugin.php, I quickly ran into the issue of if the URL has special characters from url_encode:

public function registerSiteRoutes()
{
return array(
    'myroute/(?P&lt;myVariable&gt;[-\w]+)' =&gt; array('action' =&gt; 'myPlugin/myAction')
);    
}


And then I process some variables before rendering the template in myPlugin/myAction:

 public function actionLoadTemplate( array $variables = array() )
 {
   /*
   process &amp; build $variables
   */

    $this-&gt;renderTemplate('layouts/forums/_entry', $variables);

 }


This works great if the route looks like myroute/check-this-out, however if the route had a special character in it, say it was "check-this-out!", it understandably leads to a 404. But with using url_encode on the URL so it looks like myroute/check-this-out%21, it still leads to a 404. 

When testing manually in the CP route section, if I create myroute/* with the token, I don't get a 404 with those special characters after using url_encode.

Is there a way to modify (?P&lt;myVariable&gt;[-\w]+) so that it works with url-safe special characters just like the CP version does?
You'll need to update the regex to allow for additional characters.  For example, if you want to allow !, then this will work:

return array(
    'myroute/(?P&lt;myVariable&gt;[-\w\!]+)' =&gt; array('action' =&gt; 'myPlugin/myAction')
); 


Note that \w is essentially the same as writing [A-Za-z0-9_].