Advertisement
Guest User

Untitled

a guest
Jun 11th, 2016
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. public class ReplaceTag {
  8. public static void main(String[] args) throws IOException {
  9. BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
  10.  
  11. String input = bfr.readLine();
  12.  
  13. StringBuilder str = new StringBuilder();
  14.  
  15. while (!input.equals("end")) {
  16.  
  17. str.append(input);
  18.  
  19. input = bfr.readLine();
  20. }
  21.  
  22. String text = str.toString();
  23.  
  24. Pattern htmlPattern = Pattern.compile("<a\\shref=(.+?)>(.+?)</a>");
  25. Matcher htmlMatcher = htmlPattern.matcher(text);
  26.  
  27. while (htmlMatcher.find()){
  28. String firstText = htmlMatcher.group(1);
  29. String secondText = htmlMatcher.group(2);
  30.  
  31. text = htmlMatcher.replaceAll("[URL href=" + firstText + "]" + secondText + "[/URL]");
  32. }
  33.  
  34. System.out.println(text);
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement