What is the difference between these two regular expressions :
[a-zA-Z!@#$%^&*()_=;.?]+[0-9]+
and
[a-zA-Z]+[!@#$%^&*()_=;.?][0-9]+
A token can start with multiple alphabetical characters and will end with number sequence . It can also start with one special character and will end with number sequence .
First regex breaks the string jkl3242oij92384nji332332!23#900&6382^832983@7729.979797_70979797
into the desired tokens but second doesn't. Why ?
How do I implement the concept, that only one special character is allowed ?
After I got that right:
([a-zA-Z]+|[!@#$%^&*()_=;.?])[0-9]+
Starts with multiple alphanumerical or one special and ends with digits only.
The difference is that regex #1: [a-zA-Z!@#$%^&*()_=;.?]+[0-9]+
will break a string into tokens of at least one of the characters: [a-zA-Z!@#$%^&*()_=;.?]
followed by at least on number [0-9]
.
Regex #2: [a-zA-Z]+[!@#$%^&*()_=;.?][0-9]+
on the other hand, will break a string into tokens of at least one letter [a-zA-Z]
, followed by one of [!@#$%^&*()_=;.?]
, followed by at least one number [0-9]
.
并不是您问题的真正答案,但是我发现这是调试正则表达式的非常有用的工具: https : //www.debuggex.com/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.