再求一个正则表达式

fdy1984 2009-06-03 02:54:50

String str = "select a, // 想要a
tbl.b, // 想要b
tbl.c d, // 想要d
decode(tbl.e, '1', 1, 0) f // 想要f
from sad tbl"


想把被搜索的项目名字提取出来


...全文
55 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
bigpretty 2009-06-03
  • 打赏
  • 举报
回复
"select\\s(.*)\\stb1\\.(.*)…………" 调用里面的正则库就可以了,把要提取出来的用括号扩起来,用.group()就可以提取出来了,具体的你自己看看你的字符串是什么样子的,我仅仅写了前面的一点,。
hwhack 2009-06-03
  • 打赏
  • 举报
回复
sorry,Matcher m = p.matcher("aaaaab"); 写错了,
应该是Matcher m = p.matcher("str");
hwhack 2009-06-03
  • 打赏
  • 举报
回复

你那个是从数据库里查找数据,
String str = "select a, // 想要a
tbl.b, // 想要b
tbl.c d, // 想要d
decode(tbl.e, '1', 1, 0) f // 想要f
from sad tbl"
pstmt=conn.preparedStatement(str);
rs=p.executeQueary();
//[a,b,d,f]{1,}找的是结构,而不是字段,我也不知道怎么解决,期待高手。
Pattern p = Pattern.compile("[a,b,d,f]{1,}");
Matcher m = p.matcher("aaaaab");
boolean b = m.matches();
fdy1984 2009-06-03
  • 打赏
  • 举报
回复
沙发舒服么

62,615

社区成员

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

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