拆分字符串具有带正则表达式的符号(许多管道)(Split string has symbols(many pipes) with regex)

编程入门 行业动态 更新时间:2024-10-23 07:39:19
拆分字符串具有带正则表达式的符号(许多管道)(Split string has symbols(many pipes) with regex)

我有字符串word1|word2||||word3||word4| ,我试过line.split("\\|"); 但是这只会分割一个管道,可以处理我的情况的正则表达式是什么。

I have string word1|word2||||word3||word4| , i tried line.split("\\|"); but this will split just one pipe what's the regex that can handle my case.

最满意答案

您可以使用"\\|+"来匹配多个(1个或更多)管道。

line.split("\\|+");

Ideone演示

You can use "\\|+" to match multiple (1 or more) pipes.

line.split("\\|+");

Ideone Demo

更多推荐

本文发布于:2023-08-07 03:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1461248.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   符号   管道   正则表达式   Split

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!