I want to split a string into N number of 2char strings. I know I must use String.subSequence. However I want it to keep creating these until the string is > 2
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Try this:
The regex works as follows: find any position after 2 characters (zero-width postive look behind
(?<=...)) starting from the last match position (\G) and before at least one more character (zero-width positive look ahead(?=.)). This should not match the positions at the start and end of the string and thus n can be as big as you want without resulting in an empty string at the start or the end.Edit: if you want to split as much as possible, just leave out the second parameter to split.
Example: