Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java正则表达式代码标题_Java_Regex - Fatal编程技术网

Java正则表达式代码标题

Java正则表达式代码标题,java,regex,Java,Regex,我需要一个html标签标题上的“Java正则表达式”,但它不起作用。为什么? Pattern.compile("\\<td class=\"codeTitle\">(.*)\\</td>"); Matcher m = p.matcher("<td class="codeTitle">Java RegEx</td>"); Pattern.compile(“\\(.*)\\”; Matcher m=p.Matcher(“Java正则表达式”); 您

我需要一个html标签标题上的“Java正则表达式”,但它不起作用。为什么?

Pattern.compile("\\<td class=\"codeTitle\">(.*)\\</td>");

Matcher m = p.matcher("<td class="codeTitle">Java RegEx</td>");
Pattern.compile(“\\(.*)\\”;
Matcher m=p.Matcher(“Java正则表达式”);

您需要调用
m.find()
检查是否找到匹配项。如果找到匹配项,您可以使用
m.group(1)
访问它们

此外,我认为您忘了转义主题字符串

Pattern.compile("<td class=\"codeTitle\">(.*?)</td>"); //lazy matching is better in matching html tags

Matcher m = p.matcher("<td class=\"codeTitle\">Java RegEx</td>"); // you didn't escape that

if(m.find()){
  //do something with m.group(1) which contains "Java Regex"
}
else {
  //no matches found
}
Pattern.compile((*?)//惰性匹配在匹配html标记时更好
Matcher m=p.Matcher(“Java正则表达式”);//你没有逃脱
if(m.find()){
//对包含“javaregex”的m.group(1)执行一些操作
}
否则{
//没有找到匹配项
}

您需要调用
m.find()
检查是否找到匹配项。如果找到匹配项,您可以使用
m.group(1)
访问它们

此外,我认为您忘了转义主题字符串

Pattern.compile("<td class=\"codeTitle\">(.*?)</td>"); //lazy matching is better in matching html tags

Matcher m = p.matcher("<td class=\"codeTitle\">Java RegEx</td>"); // you didn't escape that

if(m.find()){
  //do something with m.group(1) which contains "Java Regex"
}
else {
  //no matches found
}
Pattern.compile((*?)//惰性匹配在匹配html标记时更好
Matcher m=p.Matcher(“Java正则表达式”);//你没有逃脱
if(m.find()){
//对包含“javaregex”的m.group(1)执行一些操作
}
否则{
//没有找到匹配项
}

什么不起作用?要获取
(.*)
的值,需要使用.Pattern p=Pattern.compile(“\\(.*)\\”;Matcher m=p.Matcher(“Java正则表达式”);这个代码工作,但当我使用;Pattern.compile(“\\(.*)\\”;Matcher m=p.Matcher(“Java正则表达式”);不起作用:我要努力弄清楚什么不起作用,为什么不起作用,以及你期望它做什么。什么不起作用?要获取
(.*)
的值,需要使用.Pattern p=Pattern.compile(“\\(.*)\\”;Matcher m=p.Matcher(“Java正则表达式”);这个代码工作,但当我使用;Pattern.compile(“\\(.*)\\”;Matcher m=p.Matcher(“Java正则表达式”);不起作用:做一些努力,弄清楚什么不起作用,为什么不起作用,以及你期望它做什么。