简体   繁体   English

使用正则表达式模式的奇怪行为

[英]Strange behavior with Regex pattern

I'm using the following regular expression to match 0 or more characters of any kind not including -,$,] 我正在使用以下regular expression来匹配任何类型的0个或更多字符,不包括 - ,$,]

Regex Expression: 正则表达式:

(.*[^\-\$\]])

Is this the correct expression for doing this? 这是正确的表达方式吗? When I try it on the following string "hello-world" it doesn't seem to exclude the - 当我在下面的字符串“hello-world”上尝试时,它似乎并不排除 -

You are matching any character including those characters an arbitrary number of times, followed by a single character that isn't one of those characters (ie your regex only dictates that those characters can't appear at the end of the string). 您匹配任意字符( 包括那些字符的任意次数),后跟一个不是其中一个字符的字符(即您的正则表达式只表示这些字符不能出现在字符串的末尾 )。 You want this: 你要这个:

[^\-\$\]]*

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM