开发者

groovy: how to escape "(" regex etc in textarea?

I 开发者_高级运维have some text area field in my grails application. I got the following errors:

.PatternSyntaxException: Unmatched closing ')' near index 36 Name: note: 1) data listing ....

how could i escape the regular expressions in the text area field?

thanks.


The same as in a literal: place a backslash before it:

\(

EDIT: But if none of the characters from the text area must be treated special, try:

String escapedContents = java.util.regex.Pattern.quote(textArea.getText());
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜