【高分求解】帮忙看看这个正则表达式

acoding 2013-07-18 07:24:24
String currentLine = "namespace POA_circuitCutMgr";
if(currentLine.matches("\\bnamespace[ ]POA_.*")
{
System.out.println("ok");
}

问题1:我只是想匹配以namespace POA_开头的任意字符串, 这里为什么匹配不成功? 我用正则表达式工具,是可以匹配成功的。
...全文
143 7 打赏 收藏 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
linchunda 2013-07-18
  • 打赏
  • 举报
回复
引用 1 楼 oh_Maxy 的回复:
为啥不使用String的startsWith("namespace POA_");
多简单,呵呵
茫茫大海 2013-07-18
  • 打赏
  • 举报
回复
引用 5 楼 hudie1234567 的回复:
String currentLine = "namespace POA_circuitCutMgr"; if(currentLine.matches("\\bnamespace[ ]POA_.*")); { System.out.println("ok"); } 看红色的部分。
错了,后面多了个分号。
茫茫大海 2013-07-18
  • 打赏
  • 举报
回复
String currentLine = "namespace POA_circuitCutMgr"; if(currentLine.matches("\\bnamespace[ ]POA_.*")); { System.out.println("ok"); } 看红色的部分。
流星陨落 2013-07-18
  • 打赏
  • 举报
回复
执执念 2013-07-18
  • 打赏
  • 举报
回复
楼主的代码能编译通过???
nmyangym 2013-07-18
  • 打赏
  • 举报
回复

public class TestRegular 
{
	public static void main(String[] args)
	{	
		String currentLine = "namespace POA_circuitCutMgr";
		if(currentLine.matches("\\bnamespace[ ]POA_.*"))//这加个")"
		{
			System.out.println("ok");
		}
	}
}

运行结果: ok
oh_Maxy 2013-07-18
  • 打赏
  • 举报
回复
为啥不使用String的startsWith("namespace POA_");

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧