一个正则的问题
Jun 23, 2016 pm 02:39 PM
1 |
|
匹配不上,有什么好的解决方案。
回复讨论(解决方案)
你最好讲一下你的需求吧,中间那段看你的正则很乱。
1 |
|
1 |
|
使用了这个:
1 |
|
结果:
1 |
|
1 |
|
如果$s = 'dj%23999';则不行。
使用了这个:
1 |
|
[/code]
这个串也需要匹配的:$string='dj%23999';
$s = 'dj%23999';
preg_match('/([^%]+)((?:%(?:a3|23))+)(.+)/', $s, $r);
或
preg_match('/([^%]+)((?:%a3|%23)+)(.+)/', $s, $r);
正则表达式规则说明中有:
| 运算时如果发生歧义,则需要逐个开列或用括号括起来
显然 (?:%a3|23) 中 % 被结合到了 a3 从而发生了歧义
老大,能不能帮我解释下,我看到有很多的正则前面都加?:我想知道这个有什么意义?
(?:...) 与 (...) 分组作用一样,但结果不出现结果集中
(?:...) 与 (...) 分组作用一样,但结果不出现结果集中
老大,能不能帮我匹配个地址,如:
www.sohu.com,www.baidu.com,www.yahoo.com.n
这样连着的网址最多为9个,其中也可以匹配sohu.com,baidu.com,yahoo.com.cn
(?!(w))(\w+(-\w+)*)(\.(\w+(-\w+)*))*

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel

Simplified HTTP Response Mocking in Laravel Tests

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

Build a React App With a Laravel Back End: Part 2, React

12 Best PHP Chat Scripts on CodeCanyon
