简体   繁体   English

正则表达式,删除“ <xxxxxxx> ”中的一个字符串

[英]Regex, removing “<xxxxxxx>” from a string

I have a String like this 我有这样的字符串

"<xxxxxx125xxxx>

<yy2yy>2</yy2yy>
<yy3yy>3</yy3yy>
<yyhhhhyy>50</yyyyy>
<yyyyy>123</yyyyy>"

How can I have an output like: 如何获得类似以下的输出:

2 3 50 123

Well, i'm using Android, but I think that it's a global regex right? 好吧,我正在使用Android,但我认为这是全球正则表达式吧?

Simply use <[^>]+> regex. 只需使用<[^>]+>正则表达式即可。

    String[] string = new String[] { "<yy2yy>2</yy2yy>", "<yy3yy>3</yy3yy>",
            "<yyhhhhyy>50</yyyyy>", "<yyyyy>123</yyyyy>" };

    for (String s : string) {
        System.out.println(s.replaceAll("<[^>]+>", ""));
    }

output: 输出:

2
3
50
123

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM