diff --git a/system/application/config/routes.php b/system/application/config/routes.php
index 622bf88..5167f75 100644
--- a/system/application/config/routes.php
+++ b/system/application/config/routes.php
@@ -46,4 +46,6 @@
// Define your own routes below -------------------------------------------
+$route['products\/([a-z]+)\/(\d+)'] = "$1/a$2";
+
?>
\ No newline at end of file
diff --git a/system/libraries/Router.php b/system/libraries/Router.php
index abc253e..b61dfb7 100644
--- a/system/libraries/Router.php
+++ b/system/libraries/Router.php
@@ -300,16 +300,27 @@
}
// Loop through the route array looking for wildcards
- foreach ($this->routes as $key => $val)
+ foreach (array_slice($this->routes, 1) as $key => $val)
{
if (count(explode('/', $key)) != $num)
continue;
-
- if (preg_match("|".str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key))."$|", $uri))
- {
+
+ // Convert wildcards to RegEx
+ $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key));
+
+ // Does the regex match this URI ?
+ if (preg_match('|^'.$key.'$|', $uri))
+ {
+ // Do we have a replacemnt?
+ if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE)
+ {
+ $val = preg_replace('|^'.$key.'$|', $val, $uri);
+ }
+
$this->_compile_segments(explode('/', $val), TRUE);
break;
}
+
}
}
// END set_method()
diff --git a/user_guide/general/changelog.html b/user_guide/general/changelog.html
index 0bcb165..a03d6b1 100644
--- a/user_guide/general/changelog.html
+++ b/user_guide/general/changelog.html
@@ -69,8 +69,9 @@
<ul>
<li>Added <a href="hooks.html">Hooks</a> feature, enabling you to tap into and modify the inner workings of the framework without hacking the core files.</li>
-<li>Added the ability to <a href="base_classes.html">replace core system classes</a> with your own classes.</li>
+<li>Added the ability to <a href="core_classes.html">replace core system classes</a> with your own classes.</li>
<li>Added support for % character in URL.</li>
+<li>Updated the <a href="routing.html">Routing feature</a> to accept regular expressions within routing rules.</li>
<li>Moved the MIME type array out of the Upload class and into its own file in the applications/comfig/ folder.</li>
<li>Removed a strtolower() call that was changing URL segments to lower case.</li>
<li>Deprecated the hash() function due to a naming conflict with a native PHP function with the same name. Please use dohash() instead.</li>
diff --git a/user_guide/general/routing.html b/user_guide/general/routing.html
index c6e8bd9..977698b 100644
--- a/user_guide/general/routing.html
+++ b/user_guide/general/routing.html
@@ -85,8 +85,13 @@
<h2>Setting your own routing rules</h2>
-<p>Routing rules are defined in your <var>application/config/routes.php</var> file. In it you'll see an array called <dfn>$route</dfn>, that
-you can use to specify your own routing criteria. A typical route might look something like this:</p>
+<p>Routing rules are defined in your <var>application/config/routes.php</var> file. In it you'll see an array called <dfn>$route</dfn> that
+permits you to specify your own routing criteria. Routes can either be specified using <dfn>wildcards</dfn> or <dfn>Regular Expressions</dnf>
+
+
+<h2>Wildcards</h2>
+
+<p>A typical wildcard route might look something like this:</p>
<code>$route['product/:num'] = "catalog/product_lookup";</code>
@@ -125,8 +130,21 @@
<p class="important"><strong>Important:</strong> Do not use leading/trailing slashes.</p>
+<h2>Regular Expressions</h2>
-<h2>Reserved Route</h2>
+<p>If you prefer you can use regular expressions to define your routing rules. Any valid regular expression is allowed, as are back-references.</p>
+
+<p class="important"><strong>Note:</strong> If you use back-references you must use the dollar syntax rather then the double backslash syntax.</p>
+
+<p>A typical RegEx route might look something like this:</p>
+
+<code>$route['products\/([a-z]+)\/(\d+)'] = "$1/id_$2";</code>
+
+<p>In the above example, a URI similar to <dfn>products/shirts/123</dfn> would instead call the <dfn>shirts</dfn> controller class and the <dfn>id_123</dfn> function.</p>
+
+<p>You can also mix and match wildcards with regular expressions.</p>
+
+<h2>Reserved Routes</h2>
<p>There are two reserved routes:</p>
@@ -144,6 +162,11 @@
+
+
+
+
+
</div>
<!-- END CONTENT -->