2

I have the following regex for capturing links in tags (the tags are given in a string without the angular brackets):

^a .*href=['\"]([^'\"]*)['\"].*

and I have the following string:

a href="/wiki/Hypertext_Transfer_Protocol" title="Hypertext Transfer Protocol"

And this string isn't captured by the regex. It seems fine to me, can you tell me what's wrong?

Amir Rachum
  • 76,817
  • 74
  • 166
  • 248

1 Answers1

2

For Java's java.util.regex package, Matcher.match only matches when the whole input sequence matches the regex. If you want to search a text inside another, use matcher.find instead. And of course, you have to reset the matcher between matches if you don't want the second find to start searching after the end of the first one.

Paŭlo Ebermann
  • 73,284
  • 20
  • 146
  • 210