I am trying to use regex to separate complete sentences in a large block of text. I cannot use SeparatedByCharactersInSet components because it obviously fails with sentences ending with?!, !!, ... I saw some external classes to do componentSeparateByRegEx, but I prefer to do this without adding an external library.
Here is an example input
Hi, I'm testing. How are you? Wow !! this is the best and i am happy.
The output must be an array
first element: Hello, I'm testing.
second element: how are you?
third element: wow !!
The next element: this is the best, and I am happy.
This is what I have, but, as I said, he should not do what I intend. The regular expression will probably be much better here.
-(NSArray *)getArrayOfFullSentencesFromBlockOfText:(NSString *)textBlock{
NSMutableCharacterSet *characterSet = [[NSMutableCharacterSet alloc] init];
[characterSet addCharactersInString:@".?!"];
NSArray * sentenceArray = [textBlock componentsSeparatedByCharactersInSet:characterSet];
return sentenceArray;
}
Thank you for your help,
source
share