验证字符串而不是字符集

时间:2021-11-17 20:30:07

I'm validating user input, but it fails because it checks for any character in the character set as well.

我验证用户输入,但它失败了,因为它检查字符集中的任何字符。

How to assure that I can accept URI like:

如何保证我可以接受URI,比如:

e/1test1
page1/2test2
p/3test3
pag/4test4
test/63tedddddst/test5

but not when 'page' exist as a first word followed by '/':

但当“page”作为第一个单词出现,后面跟着“/”时就不是这样了:

page/test7

The expression:

表达式:

^([^page].+?\/?)$

https://regex101.com/r/zP0tQ3/1

https://regex101.com/r/zP0tQ3/1

1 个解决方案

#1


2  

How about using a negative lookahead:

如何使用消极的前瞻:

^(?!page\/).+$

Regex101

Regex101

#1


2  

How about using a negative lookahead:

如何使用消极的前瞻:

^(?!page\/).+$

Regex101

Regex101