Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/314.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 将段落从文本文件匹配到html文件,忽略html标记_Java_Regex - Fatal编程技术网

Java 将段落从文本文件匹配到html文件,忽略html标记

Java 将段落从文本文件匹配到html文件,忽略html标记,java,regex,Java,Regex,我需要一个正则表达式来匹配文本文件和html文件 "<b>Dog</b> and Cat" 我正在使用Java。下面是您需要的代码段 String text, html; BufferedReader br; int i;int tags=0; br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter HTML code");//If you want to r

我需要一个正则表达式来匹配文本文件和html文件

"<b>Dog</b> and Cat"

我正在使用Java。

下面是您需要的代码段

String text, html;
BufferedReader br;
int i;int tags=0;

br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter HTML code");//If you want to read ferom file, replace the code
html=br.readLine();
for(i=0;i<html.length();i++){
if(html.charAt(i)=='<'){tags++;continue;}
if(html.charAt(i)=='>'){tags--;continue;}
if(tags==0)text=text+html.charAt(i);
}
字符串文本,html;
缓冲剂;
int i;int标签=0;
br=新的BufferedReader(新的InputStreamReader(System.in));
System.out.println(“输入HTML代码”)//如果要读取ferom文件,请替换代码
html=br.readLine();

对于(i=0;i用
替换
和compare。从html获取该文本的起始索引,但在比较时忽略标记,这可能是重复的吗?。该函数的返回值必须是索引号。我正在尝试在该位置插入一些字符。感谢第一个答案。这很有帮助me@mois如果有帮助,则选择m左侧的勾号不确定的回答
String text, html;
BufferedReader br;
int i;int tags=0;

br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter HTML code");//If you want to read ferom file, replace the code
html=br.readLine();
for(i=0;i<html.length();i++){
if(html.charAt(i)=='<'){tags++;continue;}
if(html.charAt(i)=='>'){tags--;continue;}
if(tags==0)text=text+html.charAt(i);
}