正则表达式忽略两个字符串之间的字符?

时间:2015-01-14 15:26:24

标签: java regex regex-greedy

我的字符串是

           **abcd
           *[abc]
           <td> **Welcome
               **Welcome Again
           </td>

他们可以用任何方式删除标签之间的*符号,这样我的最终字符串就像是

            **abcd
             *[abc]
          <td> Welcome
               Welcome Again
           </td>

此处<td></td>之间的所有*都已删除 我不想使用字符串。

1 个答案:

答案 0 :(得分:1)

试试这个,

    if (s.contains("<td>"))
    {
        String first = s.substring(0, s.indexOf("<td>"));
        String last = s.substring(s.indexOf("<td>"), s.indexOf("</td>") + 5);

        System.out.println("result  : "+first + last.replace("**", ""));
    }
    else
    {
        System.out.println("result : "+s);
    }
相关问题