Help create a regular expression. I have the regular expression '~^/example/(\d+)$~' , it matches any string starting with "/ example /" and ending with a number. I need the same thing, only so that instead of the last slash there is a grid. I thought it would work like '~^/example#(\d+)$~' , but no, it doesn't plow.
UPD:
- The regular expression successfully processes such a string / example / 2
- The regular expression should find all the lines of such a plan / example # 2, / example # 3, / example # 425
- I tried instead of a slash to put \ x23, did not help
Perhaps the fact is that in the code they are processed by me like this, this is a single entry point on the site
$this->controllerFound = false; foreach ($this->routes as $key=>$value){ if(preg_match("$key", $this->request_URI,$matches)){ include_once ROOT.'/Controllers/'.$value['controller'].'.php'; $Controller = new $value['controller'](); array_shift($matches); $this->controllerFound = call_user_func_array(array($Controller, $value['action']), $matches); if ( $this->controllerFound == true) { break; } } } $this->routes is an array
$routes= array( '~^/$~' => array( 'controller' => 'MainPagesController', 'action' => 'homePage' ), '~^/list/(\w+)$~' => array( 'controller' => 'MainPagesController', 'action' => 'coursesListPage' ), '~^/course/(\d+)$~' => array( 'controller' => 'MainPagesController', 'action' => 'coursePage' ), '~^/example#(\d+)$~' => array( 'controller' => 'MainPagesController', 'action' => 'commentsPage' ), '~^/comments_jq~' => array( 'controller' => 'MainPagesController', 'action' => 'comments_jq' ) );
#=\x23- Andrey Fedorov^/example#(\d+)$will find a match in/example#123. - Wiktor Stribiżew 5:33 pm~- Wiktor Stribiżew pm