T
Ted Hopp
I was writing a quick-and-dirty regex to search html text and pull out the
source url from IMG tags. I first tried:
Pattern p = Pattern.compile("<img (?:[^>]* )?src=\"([^\"]*)\"");
(I know that this pattern makes all kinds of unwarranted assumptions about
the html, but that's another topic.) The problem I was having was that
although this pattern matches, it only results in one capture group--group
0. I was expecting the parens after src= to give me the url in capture group
1, but no such luck. It's only when I double the parens:
Pattern p = Pattern.compile("<img (?:[^>]* )?src=\"(([^\"]*))\"");
that the src value is captured.
So my question is: why do I need to double the parens?
Thanks,
Ted Hopp
source url from IMG tags. I first tried:
Pattern p = Pattern.compile("<img (?:[^>]* )?src=\"([^\"]*)\"");
(I know that this pattern makes all kinds of unwarranted assumptions about
the html, but that's another topic.) The problem I was having was that
although this pattern matches, it only results in one capture group--group
0. I was expecting the parens after src= to give me the url in capture group
1, but no such luck. It's only when I double the parens:
Pattern p = Pattern.compile("<img (?:[^>]* )?src=\"(([^\"]*))\"");
that the src value is captured.
So my question is: why do I need to double the parens?
Thanks,
Ted Hopp