Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我怎样才能写一个正则表达式来匹配,
不包含下划线“_”的字符串。
/^[^_]*$/
[^] 语法的意思是“不包括任何这些字符”。
要匹配一个不是下划线的字符,你会使用[^_](^意思是“不是”)。因此,要匹配整个字符串,您可以执行以下操作:
[^_]
^
/[^_]+/