如何在较小和较大之间找到文本,然后在Java中删除<>?

Sto*_*rit 2 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> .
Run Code Online (Sandbox Code Playgroud)

当我搜索<>谷歌时,我不知道搜索的原因,它将被忽略.需要帮助如何获得此字符串.

所以我会得到<location>,<plural-noun>,<location>,<adjective>,<location>

我必须使用这种charAt()方法.我的尝试:

String string = this.fileName;
for(int i = 0; i < string.length(); i++)
                if((string.charAt(i) == '<') && (string.charAt(i) == '>'))
                    System.println(""); //<-------- IM STUCK HERE
Run Code Online (Sandbox Code Playgroud)

我不知道......差不多两天没睡觉了.

我目前但最后一个问题......如何移除<>显示每个单词?

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++;
         }
Run Code Online (Sandbox Code Playgroud)

hat*_*ata 5

你可以使用PatternMatcher类.

  1. 搜索正则表达式模式<.*?>.
  2. 使用Matcher查找模式.