Regular expression to remove a substring between two characters

前端 未结 3 1346
温柔的废话
温柔的废话 2021-02-13 13:25

I want to remove anything between < and > including (< and >) from my string with regular expression. Here are fe

相关标签:
3条回答
  • 2021-02-13 14:15

    Try using the regex:

    <.*?>
    

    For example:

    String s = "Hi<friends>and<family>";
    System.out.println(s.replaceAll("<.*?>", ""));
    
    0 讨论(0)
  • 2021-02-13 14:17
    String newStr = str.replaceAll("<[^>]*>", "");
    
    0 讨论(0)
  • 2021-02-13 14:29

    Give this code segment a try!

    String str = "Hi<family>and</family>test";       
    
    for (int i = 0; i < str.split("</?[a-z]+>").length; i++)
      System.out.println(str.split("</?[a-z]+>")[i]);
    
    0 讨论(0)
提交回复
热议问题