Shaunak Shaunak - 4 months ago 8
iOS Question

Have different color for first sentence and then the sentence starting after 2 break lines

Please see the attached screenshot that looks similar to Notes iOS app. But here in this the user would be typing in the menu in the

UITextView
and I want to identify the menu category and have different text color for it. Each menu item would be separated by a single break line. How could I achieve this? Would this be acheivable by using a Regex expression? Any sample code would be very helpful.

enter image description here

Answer

The following PCRE-Compitible regex should do the work:

((?<=\n\n)|\A).+

It either matches the first line of your text or a line which follows two newline-characters.