【问题标题】:extract the string between last open tag and first closed tag in android提取android中最后一个打开标签和第一个关闭标签之间的字符串
【发布时间】:2019-02-19 11:51:40
【问题描述】:

我想获取标签之间的字符串,如下所示

例如:

输入 <p><b><i><u>hello</u></i></b>prajakta</p>

输出:hello

我只想得到字符串

<u>hello</u> 这应该是输出,因为它以 <u> 开头并以 </u> 结尾

【问题讨论】:

  • 那么,您希望输出为prajakta,对吗?
  • 不,应该是hello,因为它以相同的标签开始和结束

标签: java android string tags


【解决方案1】:

检查这个 -

  public static void main(String[] args) {

    String stringToSearch = "<p><b><i><u>hello</u></i></b>prajakta</p>";

    // the pattern we want to search for
    Pattern p = Pattern.compile("<p><b><i><u>(\\S+)</u></i></b>");
    Matcher m = p.matcher(stringToSearch);

    // if we find a match, get the group 
    if (m.find()) {

      // get the matching group
      String codeGroup = m.group(1);

      // print the group
      System.out.format("'%s'\n", codeGroup);

    }

  }

输出 - '你好'

【讨论】:

  • 谢谢!!但字符串并不总是相同的。可以有不同的标签,标签的数量也可以不同。
猜你喜欢
  • 1970-01-01
  • 2019-05-06
  • 2016-05-12
  • 2016-08-12
  • 1970-01-01
  • 1970-01-01
  • 2011-06-10
  • 1970-01-01
相关资源
最近更新 更多