I'm trying to do my homework but regex is new for me and I'm not sure why my code doesn't work. That's what I have to do:
Write a program that replaces in a HTML document given as string all the tags
<a href=…>…</a>
with corresponding tags[URL href=…]…[/URL]
. Read an input, until you receive “end” command. Print the result on the console.
I wrote:
Pattern pattern = Pattern.compile("<a href=\"(.)+\">(.)+<\\/a>");
input = input.replaceAll(matcher.toString(), "href=" + matcher.group(1) + "]" + matcher.group(2) + "[/URL]");
And it throws Exception in thread "main" java.lang.IllegalStateException:
No match found for this input: href="http://softuni.bg">SoftUni</a>