Does anyone know how to write this Regular Expression?
I want to create a regex pattern to match a string which might include (`) not ('). For example: "This is Joe`s book", which is different from "This is Joe's book". I know how to 开发者_如何学JAVAmatch a string with (') but (`). So does anyone know how to write this Regular Expression?
Thanks!
This should do it...
^[^']+$
The caret inside a bracket expression [^ ]
is the negation operator.
This captures strings from start ^
to end $
containing the character range in the square brackets. Note the back-tick at the end of the range.
^([a-zA-Z0-9 \.,;:\?\!`]+)$
[^']*[`][^']*
Accept any number of characters (including 0) that are not a single quote until a you encounter a backtick, and then accept any characters (including 0) that are not a single quote after that
If you are only wanting to test that the string has a back-tick:
/`/
Should work...
If you want to test for strings with backticks that don't contain apostrophes:
/^(?!.*').*`/
Should work...
精彩评论