[SalesForce] Finding substring with regex for contents of tags

I am using regex patterns to search this string:

<tr><td>111</td><td>111@test.com</td></tr><tr><td>222</td><td>222@test.com</td></tr></table>

But always get matcher result as false, any suggestions why?

I want to substring value between <tr> and </tr>.

Pattern myPattern = Pattern.compile('\\<tr>(.*?)\\</tr>');
Matcher m = myPattern.matcher(temp);
while(m.find())
{
  .. do things
}

And also this one still not working <tr>(.*?)</tr>. I check with http://regexr.com/, but it seem ok. However, when I run the code, not working.

Original Post: https://stackoverflow.com/questions/23924814/substring-with-regex-for-between-tr-tag/23924891#23924891

Best Answer

I have executed the following code:

String temp = '<tr><td>111</td><td>111@test.com</td></tr><tr><td>222</td><td>222@test.com</td></tr></table>';
Pattern myPattern = Pattern.compile('<tr>(.*?)</tr>');
Matcher m = myPattern.matcher(temp);
while(m.find())
{
    system.debug(m.group());
}

and I got back:

13:07:45.032 (32786697)|USER_DEBUG|[6]|DEBUG|111111@test.com
13:07:45.032 (32915341)|USER_DEBUG|[6]|DEBUG|222222@test.com
Related Topic