请教正则表达式

nobody_tony 2010-03-26 01:18:08
要解析的内容: IS_HOLIDAY('10/01/2009','CAD', 'us holidsy', 'test')

正则表达式:(?i)IS_HOLIDAY\('(.*?)'(?:(?:,\s*'((?:\s*\w+)+)')*)\)

其中 Group1 : 10/01/2009
当前得到的 Group2 :test

我希望分别得到 Group 2 : CAD, Group 3 : us holidsy, Group 4 : test

请问表达式该怎么写? 谢谢!
...全文
114 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
-过客- 2010-03-27
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 thc1987 的回复:]
火龙果大哥每天都在的说
[/Quote]

那是我来少了。。。
猿敲月下码 2010-03-26
  • 打赏
  • 举报
回复
String test = "IS_HOLIDAY('10/01/2009','CAD', 'us holidsy', 'test')";
String regex = "\\'(.*?)\\'";
Matcher m = Pattern.compile(regex).matcher(test);
while (m.find()) {
System.out.println(m.group(1));
}
-过客- 2010-03-26
  • 打赏
  • 举报
回复
按你的需求,其实就是把其中的子表达式重复4次而已

String test = " IS_HOLIDAY('10/01/2009','CAD', 'us holidsy', 'test')";
String pattern = "(?i)IS_HOLIDAY\\(\\s*'([^']*)'\\s*,\\s*'([^']*)'\\s*,\\s*'([^']*)'\\s*,\\s*'([^']*)'\\)";
Matcher m = Pattern.compile(pattern).matcher(test);
if(m.find())
{
System.out.println(m.group(1));
System.out.println(m.group(2));
System.out.println(m.group(3));
System.out.println(m.group(4));
}


话说好久没见火龙果了,.NET中有Capture可以记录Group的中间过程,不知道Java中有没有
string test = "IS_HOLIDAY('10/01/2009','CAD', 'us holidsy', 'test')";
Regex reg = new Regex(@"(?i)IS_HOLIDAY\((?:(?:\s*,\s*)?'([^']*)')+\s*\)");
Match m = reg.Match(test);
foreach(Capture c in m.Groups[1].Captures)
{
richTextBox2.Text += c.Value + "\n";
}
/*-------输出---------
10/01/2009
CAD
us holidsy
test
*/
hjh811 2010-03-26
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 thc1987 的回复:]
火龙果大哥每天都在的说
[/Quote]re
猿敲月下码 2010-03-26
  • 打赏
  • 举报
回复
火龙果大哥每天都在的说
fireelf000 2010-03-26
  • 打赏
  • 举报
回复
IS_HOLIDAY\('(.*)','(.*)', '(.*)', '(.*)'\)
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 lxcnn 的回复:]
话说好久没见火龙果了,.NET中有Capture可以记录Group的中间过程,不知道Java中有没有
[/Quote]

呵呵,过客你好啊。在 Java 中好像没有 group 中间过程的捕获对象,挺郁闷的。

62,624

社区成员

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

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