【高分求解】帮忙看看这个正则表达式
String currentLine = "namespace POA_circuitCutMgr";if(currentLine.matches("\\bnamespace[ ]POA_.*")
{
System.out.println("ok");
}
问题1:我只是想匹配以namespace POA_开头的任意字符串, 这里为什么匹配不成功? 我用正则表达式工具,是可以匹配成功的。 --------------------编程问答-------------------- 为啥不使用String的startsWith("namespace POA_"); --------------------编程问答--------------------
public class TestRegular
{
public static void main(String[] args)
{
String currentLine = "namespace POA_circuitCutMgr";
if(currentLine.matches("\\bnamespace[ ]POA_.*"))//这加个")"
{
System.out.println("ok");
}
}
}
运行结果:
ok
--------------------编程问答-------------------- 楼主的代码能编译通过??? --------------------编程问答-------------------- --------------------编程问答-------------------- String currentLine = "namespace POA_circuitCutMgr";
if(currentLine.matches("\\bnamespace[ ]POA_.*"));
{
System.out.println("ok");
}
看红色的部分。 --------------------编程问答--------------------
错了,后面多了个分号。 --------------------编程问答--------------------
多简单,呵呵
补充:Java , Java SE