2022/10/20 9:17

This commit is contained in:
zyx 2022-10-20 09:17:06 +08:00
parent 8376def1d7
commit 56e026d12f
2 changed files with 5 additions and 12 deletions

View File

@ -3,10 +3,6 @@ import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/**
* @author : 张宇轩
* @createTime : 2022/10/20 - 8:28
*/
public class Exercise2 { public class Exercise2 {
public static void main(String[] args) { public static void main(String[] args) {
String htmlStr = "<html><head><title>欢迎访问武汉纺织大学主页</title></head>\n" + String htmlStr = "<html><head><title>欢迎访问武汉纺织大学主页</title></head>\n" +

View File

@ -1,18 +1,14 @@
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/**
* @author : 张宇轩
* @createTime : 2022/10/20 - 8:47
*/
public class Exercise3 { public class Exercise3 {
public static void main(String[] args) { public static void main(String[] args) {
String htmlStr = "<font face=\"Arial Serif\" size=\"10px\" color=\"red\" />"; String htmlStr = "<font face=\"Arial Serif\" size=\"10px\" color=\"red\" />" +
"<font face=\"Arial Serif\" color=\"red\" />" +
"<font size=\"10px\" color=\"red\" />";
Pattern p1 = Pattern.compile("<\\s*font\\s*([^>]*)\\s*>",Pattern.CASE_INSENSITIVE); Pattern p1 = Pattern.compile("<\\s*font\\s*([^>]*)\\s*>",Pattern.CASE_INSENSITIVE);
Matcher m1 = p1.matcher(htmlStr); Matcher m1 = p1.matcher(htmlStr);
if(m1.find()) { while (m1.find()) {
String fontStr = m1.group(); String fontStr = m1.group();
Pattern p2 = Pattern.compile("([a-z]+)\\s*=\\s*\"([^\"]+)\"",Pattern.CASE_INSENSITIVE); Pattern p2 = Pattern.compile("([a-z]+)\\s*=\\s*\"([^\"]+)\"",Pattern.CASE_INSENSITIVE);
Matcher m2 = p2.matcher(fontStr); Matcher m2 = p2.matcher(fontStr);
@ -22,6 +18,7 @@ public class Exercise3 {
eachAttribute = eachAttribute.replaceAll("\"",""); eachAttribute = eachAttribute.replaceAll("\"","");
System.out.println(eachAttribute); System.out.println(eachAttribute);
} }
System.out.println();
} }
} }
} }