import java.util.regex.Matcher;
import java.util.regex.Pattern;public class Test1 { public static void main(String[] args) {
String html = "<";
String pattern = "\\<";
//String pattern = "<"; 这个也可以
Matcher m = Pattern.compile(pattern).matcher(html);
while (m.find()) {
System.out.println(m.group());
}
}}
是面匹配
import java.util.regex.Matcher;
import java.util.regex.Pattern;public class Test1 { public static void main(String[] args) {
String html = "a";
String pattern = "\\a";
//String pattern = "<"; 这个也可以
Matcher m = Pattern.compile(pattern).matcher(html);
while (m.find()) {
System.out.println(m.group());
}
}}却不匹配,why
难大于号小于号可以特殊,即 < 与\\< 相同
面a 与\\a 却不相同
import java.util.regex.Pattern;public class Test1 { public static void main(String[] args) {
String html = "<";
String pattern = "\\<";
//String pattern = "<"; 这个也可以
Matcher m = Pattern.compile(pattern).matcher(html);
while (m.find()) {
System.out.println(m.group());
}
}}
是面匹配
import java.util.regex.Matcher;
import java.util.regex.Pattern;public class Test1 { public static void main(String[] args) {
String html = "a";
String pattern = "\\a";
//String pattern = "<"; 这个也可以
Matcher m = Pattern.compile(pattern).matcher(html);
while (m.find()) {
System.out.println(m.group());
}
}}却不匹配,why
难大于号小于号可以特殊,即 < 与\\< 相同
面a 与\\a 却不相同
解决方案 »
- java自定义对话框 为何设置为模式的,里面添加的组件就无法显示了
- 关于接口与抽象类的一些看法与讨论
- windows下环境变量设置和命令提示符里java xxx的运行
- 命令行启动eclipse
- 远光软件
- 使用java.text.DecimalFormat类,如何将类似 1,234,567.1 数字转化成 1234567.1呢?
- i++ 何时自增?
- jbuilder7 + cvs时当place project into cvs时,好多包(目录)被自动删除了,请问有知道如何解决地吗?
- Java ssl连接异常, Remote host closed connection during handshake
- 大佬们,我在做maven 时
- 给出一个日期字符串,判断这个字符串表示的日期为星期几
- 推荐学习路径
"\\a"表示的是报警(bell)符,当然不能与a匹配
(?<!X) X,通过零宽度的负 lookbehind
(?>X) X,作为独立的非捕获组 所以直接使用<文本含义时,需要转义,也就是\\<而a直接写就是文本含义,加了转义就改变意思了\a 报警 (bell) 符 ('\u0007')