正则表达式实现转义序列

时间:2015-11-18 12:31:17

标签: java regex escaping

我有一个应用程序,它接受任何字符串并在notepad中输入值。如果有任何东西被括号括起来,例如 - <domain>它变成应用程序的变量,在执行期间它要求输入值它存储并在记事本中输入相同的值。现在我的痛苦是我想在不要求它的值的情况下键入<domain>作为文本。可以跳过处理{{1}的正则表达式实现括号作为变量和类型。

1 个答案:

答案 0 :(得分:1)

作为正则表达式&lt;&gt;字符不需要转义。

以下代码证明了这一点。

String pattern = ".+<domain>.+";
String content = "this is the <domain> word";
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(content);
boolean b = m.matches();

结果是b == true,这意味着在内容中找到了模式。

相关问题