【问题标题】:Split string by specific substring按特定子字符串拆分字符串
【发布时间】:2015-12-18 04:54:12
【问题描述】:

假设我有这个字符串

[0] playerName19  [1] playerName17  [2] playerName18  [3] playerName15  [4]      playerName59  [5] playerName16  [6] playerName6  [7] playerName60

如何使用 Java 将其拆分成这样的:

[0] playerName19, [1] playerName17, [2] playerName18... 

我尝试使用 split() 但问题是 playerName 号码扩展是随机生成的,并且每个查询都会更改。

【问题讨论】:

  • 您需要将初始字符串拆分或将初始字符串更改为以逗号分隔的第二个?

标签: java regex string split substring


【解决方案1】:

根据[num]之前的空格进行分割。

string.split("\\s+(?=\\[\\d+\\])");

【讨论】:

    猜你喜欢
    • 2020-11-14
    • 2014-07-22
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 2012-04-20
    • 1970-01-01
    相关资源
    最近更新 更多