Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
所以我有这个字符串:
http://www.whatever.com/whatever-c89-ca9840-cu3849
是否可以使用唯一的正则表达式(preg_match)来:
-ca9840
9840
这就是我现在正在做的事情:
preg_match('/-cu[\d]+-/', $uri, $mathes)
<?php $url = 'http://www.whatever.com/whatever-c89-ca9840-cu3849'; if( preg_match('@-ca(\d+)@', $url, $matches) ){ var_dump($matches); }
array(2) { [0]=> string(7) "-ca9840" [1]=> string(4) "9840" }
不,就这么简单。正则表达式除了它所处的状态外没有记忆。