English 中文(简体)
2. 配对2艘冷轮驱动器路线的定期表述
原标题:Regular expression for matching 2 urls cakephp route

The 2 example of the urls:

/car/2004-audi-a*4*12149

页: 1

这是我迄今为止所做的:

[0-9]-[A-Za-z]-[A-Za-z]-[0-9]

这只符合上文所引述的第一部分。 我需要与以下部分相匹配:

car/2004-audi-a4-12149

页: 1

这可能不会对reg鱼产生任何影响,但使用这种方式的Im在面包工厂路线上:

Router::connect(
    /car/:id ,
   array( controller  =>  cars ,  action  =>  view ),
   array(
       pass  => array( id ),
       id  =>  [0-9]-[A-Za-z]-[A-Za-z]-[0-9] 
   )
);
问题回答

如果你想要达到最后一点,你就可以这样做。

d+$

如果我行不通,你能否试图再次描述模式?

The reason d+$ is not working for you stems from this code /car/:id in your route definition, you ask cake for everything after the slash to be matching the d+$ which is not the case for /car/2004-audi-a*4*-12149

I would rather pass the whole 2004-audi-a*4*-12149 as a :slug to a action and than call a regular php preg_match to extract the id using the (d+$)





相关问题
Uncommon regular expressions [closed]

Recently I discovered two amazing regular expression features: ?: and ?!. I was curious of other neat regex features. So maybe you would like to share some tricky regular expressions.

regex to trap img tag, both versions

I need to remove image tags from text, so both versions of the tag: <img src="" ... ></img> <img src="" ... />

C++, Boost regex, replace value function of matched value?

Specifically, I have an array of strings called val, and want to replace all instances of "%{n}%" in the input with val[n]. More generally, I want the replace value to be a function of the match ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

Is it possible to negate a regular expression search?

I m building a lexical analysis engine in c#. For the most part it is done and works quite well. One of the features of my lexer is that it allows any user to input their own regular expressions. This ...

regex for four-digit numbers (or "default")

I need a regex for four-digit numbers separated by comma ("default" can also be a value). Examples: 6755 3452,8767,9865,8766,3454 7678,9876 1234,9867,6876,9865 default Note: "default" ...

热门标签