[英]Regular Expression String Does Not Contain Numbers
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. 如果网址包含
/painters/1-something
则应该没有匹配。
I've been trying the following with no luck: 我一直在尝试以下运气,没有运气:
\/{1}(painters|contractors)\/?[^0-9][a-z]*
This still matches on /painters/
or /contractors/
这仍然匹配
/painters/
或/contractors/
Please advise. 请指教。
You can try this regex. 你可以试试这个正则表达式。 It uses a negative lookahead to disallow a match if a number comes after your second forward slash.
如果在第二个正斜杠之后出现一个数字,它会使用负前瞻来禁止匹配。
^\/(painters|contractors)\/(?![0-9])
Note that if you don't want number anywhere in the string you can use a negative lookahead right at the beginning. 请注意,如果您不想在字符串中的任何位置使用数字,则可以在开头使用负向前瞻。
^(?!.*[0-9])\/(painters|contractors)\/
This construct will disallow any string containing numbers. 此构造将禁止包含数字的任何字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.