【发布时间】:2011-06-01 02:00:28
【问题描述】:
我正在尝试定义一个模式来匹配其中带有问号 (?) 的文本。在正则表达式中,问号被认为是“一次或根本没有”。 那么我可以用 (\\?) 替换文本中的 (?) 符号来解决模式问题吗?
String text = "aaa aspx?pubid=222 zzz";
Pattern p = Pattern.compile( "aspx?pubid=222" );
Matcher m = p.matcher( text );
if ( m.find() )
System.out.print( "Found it." );
else
System.out.print( "Didn't find it." ); // Always prints.
【问题讨论】:
标签: java regex replace escaping