Reputation: 45
For some reason my multi delimiter split is not working. Hope it just a syntax error.
This works, but I want to also split if it finds end date
String dateList[] = test.split("(?="+StartDate+")");
But this does not. Am I missing something?
String dateList[] = text.split("[(?="+StartDate+")(?="+EndDate+")]");
Upvotes: 1
Views: 44
Reputation: 48444
You cannot use "lookarounds" in a custom character class - they'd be just interpreted as characters of the class (and may not even compile the pattern properly if a malformed range is detected, e.g. with dangling -
characters).
Use the |
operator to alternate between StartDate
and EndDate
.
Something like:
String dateList[] = text.split("(?="+StartDate+"|"+EndDate+")");
Notes
Pattern.quote
on your start and end date values, in case they contain reserved characters. camelBack
, not CamelCase
Upvotes: 2