Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Regex;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class Lab06_ReplaceTag {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- String regex = "(^|(?<=\\s))(?<replacedOne><a+) (.+?\\w\\\")(?<replacedTwo>\\>)(\\w+)(?<replacedThree>\\<\\/a\\>)";
- Pattern pattern = Pattern.compile(regex);
- while (true) {
- String input = reader.readLine();
- if ("end".equals(input)) break;
- Matcher matcher = pattern.matcher(input);
- if (!matcher.find()) {
- System.out.println(input);
- } else if (matcher.find()){
- String matchStr = "";
- while (matcher.find()) {
- matchStr = matcher.group();
- matchStr = matchStr.replaceAll("<a", "[URL");
- matchStr = matchStr.replaceAll(">", "]");
- matchStr = matchStr.replaceAll("</a", "[/URL");
- System.out.println(matchStr);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment