I got a string with the following format : yyyyMMdd_HHmm_ss_unitCode_(status). I need to map each component to a property of a dedicated class.
I thought of defining my token with a regular expression like this :
{d+}4{d+}2{d+}2_{d+}2_{d+}2_{s+}3_{s+}2
=> Apologize for the approximate regex syntax, d is for decimal and s for string.
How can I tell my parser that the first group {d+}4
must go in the "year" property of my class, the second to the "month" and so forth.
Obviously, I could just do this : token.setYear(substring(0,4))
but I wanted to be a little more generic since I do not have control over the structure of the filename.
I also considered defining an xml structure with startPosition, endPosition, attribute name to store and type.
All in all, I thought all of this much too complicated. The problem is that I do not have a single separator to enable me to use a String.split
.