开发者

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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜