我想在PHP中匹配这样的内容:
class-11/xxx/xxx/xx/xxx/things_to_remember/
class-12/xxx/xxx/xx/xxx/things_to_remember/然而,我不想匹配这样的东西:
xxx/class-11/xxx/
class-11/xxx/things_to_remember/xxx
class-11/xxx/我是这样写的:
^(class-[12]{2})/.+/things_to_remember/$我听说正则表达式有很多特性,比如贪心等等,它们也需要高效吗?上面的表情好吗?
发布于 2015-12-04 16:31:24
我在这里写了一个小正则表达式来捕捉它,就像你写的格式一样。它可能需要一些微小的改变,因为我不知道课后可能有多少位数。
/
class-(\d{2}) #Matches class, makes sure that class only is 2 digits - captures class digits
\/([^\/]{3}) #captures first 3 characters that aren't a slash.
\/([^\/]{3}) #Capture 3 characters again.
\/([^\/]{2}) #captures two characters
\/([^\/]{3}) #Captures 3 characters
\/things_to_remember\/ #Matches last piece of string.
/xg你可以在这里测试一下。
https://stackoverflow.com/questions/34092558
复制相似问题