I have a big string and I wanna take links from that string. I can print link.
Pattern pattern = Pattern.compile(".*(?<=overlay-link\" href=\").*?(?=\">).*");
with that code. Example output:
<a title="TITLE" class="overlay-link" href="LINK HERE"></a>
when I try string.replaceAll, regex deleting link and printing another variables.
EX: <a title="TITLE" class="overlay-link" href=""></a>
I am new on regex. Can you help me?
Here is full code :
String content;
Pattern pattern = Pattern.compile(".*(?<=overlay-link\" href=\").*?(?=\">).*");
try {
Scanner scanner = new Scanner(new File("sourceCode.txt"));
while (scanner.hasNext()) {
content = scanner.nextLine();
if (pattern.matcher(content).matches()) {
System.out.println(content.replaceAll("(?<=overlay-link\" href=\").*?(?=\">)", ""));
}
}
} catch (IOException ex) {
Logger.getLogger(SourceCodeExample.class.getName()).log(Level.SEVERE, null, ex);
}