Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.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_Charat - Fatal编程技术网

Java 如何查找介于小于和大于之间的文本,然后去除<&燃气轮机;在爪哇?

Java 如何查找介于小于和大于之间的文本,然后去除<&燃气轮机;在爪哇?,java,charat,Java,Charat,我不知道怎么找到这些词。。例如,我有这个文本 The other day I went to the <location> and bought some <plural-noun> . Afterwards, I went to <location> , but it was very <adjective> so I left quickly and went to <location> . 我不知道。。。几乎两天没有睡觉 我现在

我不知道怎么找到这些词。。例如,我有这个文本

The other day I went to the <location> and bought some <plural-noun> . Afterwards, I went to <location> , but it was very <adjective> so I left quickly and went to <location> .
我不知道。。。几乎两天没有睡觉

我现在还有最后一个问题。。。如何删除显示器上每个单词的

String string = this.template;
        Pattern pattern = Pattern.compile("<.*?>");
        Matcher matcher = pattern.matcher(string);

        List<String> listMatches = new ArrayList<String>();

        while(matcher.find()) {
            listMatches.add(matcher.group());
        }
        // System.out.println(listMatches.size());
        int indexNumber = 1;
         for(String s : listMatches) {
             System.out.println(Integer.toString(indexNumber) + ". " + s);
             indexNumber++;
         }
String String=this.template;
Pattern=Pattern.compile(“”);
Matcher-Matcher=pattern.Matcher(字符串);
List listMatches=新建ArrayList();
while(matcher.find()){
添加(matcher.group());
}
//System.out.println(listMatches.size());
int indexNumber=1;
用于(字符串s:listMatches){
System.out.println(Integer.toString(indexNumber)+“+s);
indexNumber++;
}

您可以使用
模式
匹配器

  • 搜索正则表达式模式
  • 使用Matcher查找模式

  • 阅读整行并将其存储在,比如说
    字符串行
    。然后,使用:

    String line = "The other day I went to the <location> and bought some <plural-noun> . Afterwards, I went to <location> , but it was very <adjective> so I left quickly and went to <location> ."; 
    
    boolean found = false;
    String data[] = new String[20];
    int counter = 0;
    
    Arrays.fill(data, "");
    
    for(int i = 0; i < line.length() && counter < 20; i++) {
        if(line.charAt(i) == '<')
            found = true;
        else if(line.charAt(i) == '>' && found) {
            found = false;
            counter++;
        }
        else if(found) {
            data[counter] += line.charAt(i);
        }
    }
    
    for(int i = 0; i < counter; i++)
        System.out.println("Scanned data #" + (i + 1) + " = " + data[i]);
    
    String line=“前几天,我去商店买了一些。后来,我去了,但天气非常好,所以我很快就离开了,去了。”;
    布尔值=false;
    字符串数据[]=新字符串[20];
    int计数器=0;
    数组。填充(数据为“”);
    对于(int i=0;i
    这里有两个问题,所以我只回答最后一个问题;当您拥有所需的
    时,按如下方式操作:

    String text = "<the_text_you_want>";
    
    text.replace("<","").replace(">","").replace("-"," ");
    
    String text=”“;
    text.replace(“,”).replace(“-”,”);
    

    这将去掉分隔符。

    为什么不使用模式的
    ?如何使用此选项匹配它<代码>模式。编译(\\[(.*?\\])我只想
    不处理这个<代码>模式模式=模式。编译(“”)它正在工作。。。您知道如何删除每个字符串上的
    吗?如果您不需要尖括号,可以尝试使用lookaheads和lookbehinds。我认为正确的表达式应该是
    Pattern.compile((?为什么必须使用charAt()方法?这可以用正则表达式来解决。@Brad更新了new…谢谢,你知道如何将
    复数名词
    更改为
    复数名词
    谢谢你的反馈!一旦你赢得了总共15个声誉,你的投票将改变公开显示的帖子分数。
    无法投票对不起,伙计…如果我成功,我会投票达到15岁
    String text = "<the_text_you_want>";
    
    text.replace("<","").replace(">","").replace("-"," ");