I know that there have been variations of questions answered here
- Match multiline text using regular expression
- Split text with Java-Regex in pairs with Regex over several lines
- Match multiline text using regular expression
I have tried to go through the solutions and come up with a regular expression for my needs. I have a string of text over multiple lines with neither a fixed starting location nor an ending location for a particular line.
<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>
I would like to extract the following the contents from javascript:goto("link")
(what ever link value represents) There are multiple such occurrences in the above regex, but the regex that I am using returns just a single occurrence. I would like to return all of it. My code block is given below
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));
}
The resultant output is always findmyinfo
and nothing else.
UPDATE - The desired outputs are
billpay (from javascript:goto('billpay');)
findmyinfo (from javascript:goto('findmyinfo');)
I would also like to to extract
/myaccounts/brain/redirect.go?target=findmyroutingnumber','ool','currentPage from OOLPopUp('/myaccounts/brain/redirect.go?target=findmyroutingnumber','ool','currentPage')