1

I'm trying to match a pattern in a url that does not include a number.

For example:

/painters/1-joe-bob/dashboard

I would only want to match urls that are the following:

/painters
/painters/string

If the url includes /painters/1-something then there should be no match.

I've been trying the following with no luck:

\/{1}(painters|contractors)\/?[^0-9][a-z]*

This still matches on /painters/ or /contractors/

Please advise.

4

1 回答 1

3

你可以试试这个正则表达式。如果数字出现在您的第二个正斜杠之后,它会使用负前瞻来禁止匹配。

^\/(painters|contractors)\/(?![0-9])

请注意,如果您不想在字符串中的任何位置使用数字,则可以在开头使用负前瞻。

^(?!.*[0-9])\/(painters|contractors)\/

此构造将禁止任何包含数字的字符串。

于 2013-10-20T22:41:35.783 回答