Obnoxious_Ninja
Obnoxious_Ninja

Reputation: 3

How to split a specific string in Java

I'm trying to create a program that will split a given string into multiple parts, then convert all to lowercase if it has two or more consecutive capital letters. After splitting the string, it would strip it of any non-alphabetical characters, convert it all to lowercase, then put the non-alphabetical characters back in. I have the logic to convert it all to lower case, but it doesn't split the string quite how I want. Currently, I'm trying to make it so that it:

I currently here's everything I have to do this stuff: http://pastebin.com/ppBykvY4

Where the "[A-Z]{2}" is for two consecutive capitals, but I don't know how I can include the rest. {Punc} would only work if I could exclude everything except "!", "?", ".".

Also, I'm using the BukkitAPI.

EXAMPLE: If a user entered all of the above examples (in the bullets), they should be:

Upvotes: 0

Views: 204

Answers (1)

Ali Gajani
Ali Gajani

Reputation: 15091

If you want multiple delimiters, use the |.

String[] message = chat.split("regex|regex|regex");

So I assume it will end up something like this:

String[] message = chat.split("[A-Z]{2}|[.!?]|[\s]");

enter image description here

Tested using: http://www.regexplanet.com/advanced/java/index.html

Upvotes: 2

Related Questions