0

Say I have this string

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

How do I split it into something like this, using Java:

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

I tried using split() but the problem is that the playerName number extension is randomly generated and changes for each query.

1
  • you need to split the initial string or change the initial string to the second one separated by comma ? Commented Sep 21, 2015 at 13:20

1 Answer 1

2

Just split according to the space which exists before [num].

string.split("\\s+(?=\\[\\d+\\])");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.