Home > Backend Development > PHP Tutorial > php-正则表达式 - toroPHP路由器正则表达式不能匹配中英文

php-正则表达式 - toroPHP路由器正则表达式不能匹配中英文

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:22:23
Original
1494 people have browsed it

各位好,最近劳烦大家了。
我今天在做博客系统的时候遇到了一个问题。
目前用的是toroPHP为路由的,它的正则表达式匹配是这样子的。

<code>$tokens = [
    ':string' => '([a-zA-Z]+)',
    ':number' => '([0-9]+)',
    ':alpha' => '([a-zA-Z0-9-_]+)',
    'char'   => '([^/])',
    'alphaslash'  => '([_0-9a-zA-Z-/])'
];
foreach ($routes as $pattern => $handler_name) {
    $pattern = strtr($pattern, $tokens);
    if (preg_match('#^/?' . $pattern . '/?$#', $path_info, $matches)) {
        $discovered_handler = $handler_name;
        $regex_matches = $matches;
        break;
    }
}</code>
Copy after login
Copy after login

目前我想匹配一段字符串,大概像:哈哈哈a 或者 哈哈哈
这样子的匹配不到。

希望大家帮我解决一下这个问题,谢谢。
试过很多正则表达式,有的只匹配中文,中英文混合的就不匹配了。

toroPHP on GITHUB:链接描述

回复内容:

各位好,最近劳烦大家了。
我今天在做博客系统的时候遇到了一个问题。
目前用的是toroPHP为路由的,它的正则表达式匹配是这样子的。

<code>$tokens = [
    ':string' => '([a-zA-Z]+)',
    ':number' => '([0-9]+)',
    ':alpha' => '([a-zA-Z0-9-_]+)',
    'char'   => '([^/])',
    'alphaslash'  => '([_0-9a-zA-Z-/])'
];
foreach ($routes as $pattern => $handler_name) {
    $pattern = strtr($pattern, $tokens);
    if (preg_match('#^/?' . $pattern . '/?$#', $path_info, $matches)) {
        $discovered_handler = $handler_name;
        $regex_matches = $matches;
        break;
    }
}</code>
Copy after login
Copy after login

目前我想匹配一段字符串,大概像:哈哈哈a 或者 哈哈哈
这样子的匹配不到。

希望大家帮我解决一下这个问题,谢谢。
试过很多正则表达式,有的只匹配中文,中英文混合的就不匹配了。

toroPHP on GITHUB:链接描述

修改正则表达式,匹配中文

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template