ruby-regex:如何匹配“/ table [number]”?

时间:2010-04-23 06:15:25

标签: ruby regex

我想匹配所有“/ table [number]”

所以像“/ table [1]”和“/ table”这样的字符串匹配。

2 个答案:

答案 0 :(得分:2)

/\/table(?:\[\d+\])?/

答案 1 :(得分:1)

根据您的需要,您可能还需要输入单词边界标记。所以

 /\b\/table(?:\[\d+\])?\b/

如果没有这些,正则表达式将匹配像
的字符串 /表
/桌面
.....