Robby Smet
Robby Smet

Reputation: 4661

Java splitting a string on char

I have the following string:

<stx>1<rs>aaaa<rs>bbbb<rs>cccc<etx>

How can i split it in a way that I get 1,aaaa,bbbb,cccc in an array?

I tried splitting on <rs> but then I get <stx>1,aaaa,bbbb,cccc in my array.

So how do I get rid of that <stx>?

stx,rs and etx are chars btw.

thx

Upvotes: 0

Views: 635

Answers (1)

MByD
MByD

Reputation: 137432

You can split with the following regex:

<\w+>

When using it in Java, don't forget to escape the \:

String[] splitted = myString.split("<\\w+>");

Upvotes: 6

Related Questions