开发者

Why doesn't this string matches my regex?

I have the following regex for capturing links in tags (the tags are given in a string without the开发者_StackOverflow中文版 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜