I am trying to write a regular expression with the following requirements:
(1) not allow #
(2) not allow &
(3) not allow \\t (tab)
(3) not allow multiple spaces (single space is ok)
Here is I tried:
^[^#&\t\s+]*$
However, I can't get my output as I want. What am I doing wrong?
Can someone help me?
This will work in many regex flavors (including PCRE and JavaScript):
^(?!.* )[^#&\t]*$
First, do a negative look-ahead to make sure there aren't any double spaces, and then match zero or more characters that aren't #
, &
, or \\t
.
把任务分成所允许的字符的基本表现,再加上负先行停泊开始为“无双空格”断言:
^(?!.* )[^#&\t]*$
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.