I want to remove anything between <
and >
including (<
and >
) from my string with regular expression. Here are few examples.
我想从正常表达式的字符串中删除 <和> 之间的任何内容,包括( <和> )。这里有几个例子。
Hi<friends>and<family>
it should give Hiand
嗨
<Rekha Verma>rekha@gmail.com
then it should give rekha@gmail.com
Reva Patel
it should give Reva Patel
Reva Patel应该给Reva Patel
<Reva Patel>revapatel@gmail.com,<rekha Verma>rekha@gmail.com
it should give revapatel@gmail.com,rekha@gmail.com
Can anyone please give me a regular expression for this? I need to implement it in Java.
有人可以给我一个正则表达式吗?我需要用Java实现它。
3 个解决方案
#1
16
Try using the regex:
尝试使用正则表达式:
<.*?>
For example:
例如:
String s = "Hi<friends>and<family>";
System.out.println(s.replaceAll("<.*?>", ""));
#2
4
String newStr = str.replaceAll("<[^>]*>", "");
#3
0
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]);
#1
16
Try using the regex:
尝试使用正则表达式:
<.*?>
For example:
例如:
String s = "Hi<friends>and<family>";
System.out.println(s.replaceAll("<.*?>", ""));
#2
4
String newStr = str.replaceAll("<[^>]*>", "");
#3
0
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]);