【发布时间】:2014-09-07 07:24:39
【问题描述】:
我知道这里回答了各种各样的问题
- Match multiline text using regular expression
- Split text with Java-Regex in pairs with Regex over several lines
- Match multiline text using regular expression
我已经尝试过解决方案,并根据我的需要提出一个正则表达式。我有一个多行的文本字符串,既没有固定的起始位置,也没有特定行的结束位置。
<a name='bill_pay' href='javascript:goto('billpay');' class='fsdnav-top-menu-item'>Bill Pay <span class='fsdnav-ada-hidden'>link and menu. Press enter to navigate to this link. Press control + space to open submenu.
To move through submenu items press tab and then press up or down arrow.</span> </a>
<a name='bill_pay' href='javascript:goto('findmyinfo');' class='fsdnav-top-menu-item'>
Bill Pay <span class='fsdnav-ada-hidden'>link and menu. Press enter to navigate to this link. Press control + space to open submenu.
To move through submenu items press tab and then press up or down arrow.</span> </a>
<a name='bill_pay' href='#' onClick='OOLPopUp('/myaccounts/brain/redirect.go?target=findmyroutingnumber','ool','currentPage');return false;' class='fsdnav-top-menu-item'>
Bill Pay <span class='fsdnav-ada-hidden'>link and menu. Press enter to navigate to this link. Press control + space to open submenu.
To move through submenu items press tab and then press up or down arrow.</span> </a>
我想从javascript:goto(&quot;link&quot;) 中提取以下内容(链接值代表什么) 上面的正则表达式中有多个这样的事件,但我使用的正则表达式只返回一个事件。我想全部归还。我的代码块如下所示
private static final Pattern PATTERN_WITH_ASCII_QUOTES =
Pattern.compile("^.*goto\\('(\\w+)'\\).*",
Pattern.MULTILINE|Pattern.DOTALL);
// "str" is the string representation of the text above.
Matcher m = PATTERN_WITH_ASCII_QUOTES.matcher(str);
while (m.find()) {
System.out.println(m.group(1));
}
结果输出始终为findmyinfo,仅此而已。
UPDATE - 所需的输出是
billpay (from javascript:goto('billpay');)
findmyinfo (from javascript:goto('findmyinfo');)
我也想提取
/myaccounts/brain/redirect.go?target=findmyroutingnumber','ool','currentPage from OOLPopUp('/myaccounts/brain/redirect.go?target=findmyroutingnumber','ool','currentPage')
【问题讨论】:
-
你的预期输出是什么?
标签: java regex string multiline