Following are the intended output and the original output I got from using this line of code :- ArrayList<String> nodes = new ArrayList<String>
(Arrays.asList(str.split("(?i:"+word+")"+"[.,!?:;]?")));
on the input :-
input : "Cow shouts COW! other cows shout COWABUNGA! stupid cow."
The string will be split into an ArrayList at the acceptable "cow" versions.
Original Output(from line above) :
ArrayList nodes = {, shouts , other , s shout ,ABUNGA! stupid }
vs
Intended Output :
ArrayList nodes = {, shouts , other cows shout COWABUNGA! stupid }
What I'm trying to achieve :
- Case insensitive search. (ACHIEVED)
- Takes into account the possibilities of these punctuations ".,:;!?" behind the word that is to be split. hence
"[.,!?:;]?"
(ACHIEVED) - Only splits if it finds exact word lengths +
"[.,!?:;]?"
. It will not split at "cows" nor "COWABUNGA!" (NOT ACHIEVED, need help) - Find a possible way to add the acceptable splitting-word versions
{Cow,COW!,cow.}
into another arrayList for future use later in the method. (IN PROGRESS)
As you can see, I have fulfilled 1. and 2. and I am pasting this question first whilst I work on 4.. I know this issue can be solved with more extra lines but I'd like to keep it minimal and efficient.
UPDATE : I found that "{"+input.length+"}"
can limit the matches down to letter length but I don't know if it'll work or not.
All help will be appreciated. I apologize if this question is too trivial but alas, I am new. Thanks in advance!