forked from janbodnar/Java-Advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaRegexReplacingStrings.java
More file actions
33 lines (24 loc) · 998 Bytes
/
JavaRegexReplacingStrings.java
File metadata and controls
33 lines (24 loc) · 998 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.zetcode;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
public class JavaRegexReplacingStrings {
public static void main(String[] args) throws MalformedURLException, IOException {
URL url = new URL("http://www.something.com");
try (InputStreamReader isr = new InputStreamReader(url.openStream(),
StandardCharsets.UTF_8);
BufferedReader br = new BufferedReader(isr)) {
String content = br.lines().collect(Collectors.joining(System.lineSeparator()));
Pattern p = Pattern.compile("<[^>]*>");
Matcher matcher = p.matcher(content);
String stripped = matcher.replaceAll("");
System.out.println(stripped);
}
}
}