what is the regular expression for "No multiple hyphens or double quotes permited!"
Can anyone told me how to开发者_运维问答 write this regex for "No multiple hyphens or double quotes permited!"? I tried [^"--]*. But good-looking is not gonna passed.
reading between the lines, it sounds to me like you might be trying to prevent a SQL injection attack by preventing the user from entering quote characters or SQL comments? If that's what you're trying to do, then this is not the way to do it.
What you actually need to do is make sure your string is properly escaped. If your SQL string is properly escaped then no amount of hyphens or quotes will cause you a problem, so there will be no need to block out hyphens or quotes, or any other dangerous characters.
I assume you just want to test a string to ensure it does not have any "
or --
i would use this:
("|--)
If there is no match, the string is OK.
If this isn't what you want, please provide more info + examples.
Paul is on the right track, but if you want a regex that evaluates to True for strings without quotes or double-hyphens, use a negative lookahead assertion:
^(?:(?!"|--).)*$
精彩评论