I would like some guidance on how to split a string into N number of separate strings based on a arithmetical operation; for example string.length()/300.
I am aware of ways to do it with delimiters such as
testString.split(",");
but how does one uses greedy/reluctant/possessive quantifiers with the split method?
Update: As per request a similar example of what am looking to achieve;
String X = "32028783836295C75546F7272656E745C756E742E657865000032002E002E005C0"
Resulting in X/3 (more or less… done by hand)
X[0] = 32028783836295C75546F
X[1] = 6E745C756E742E6578650
x[2] = 65000032002E002E005C0
Dont worry about explaining how to put it into the array, I have no problem with that, only on how to split without using a delimiter, but an arithmetic operation
You could do that by splitting on
(?<=\G.{5})whereby the stringaaaaabbbbbccccceeeeefffwould be split into the following parts:The
\Gmatches the (zero-width) position where the previous match occurred. Initially,\Gstarts at the beginning of the string. Note that by default the.meta char does not match line breaks, so if you want it to match every character, enable DOT-ALL:(?s)(?<=\G.{5}).A demo:
which can be tested online here: http://ideone.com/q6dVB
EDIT
Since you asked for documentation on regex, here are the specific tutorials for the topics the suggested regex contains:
\G, see: http://www.regular-expressions.info/continue.html(?<=...), see: http://www.regular-expressions.info/lookaround.html{...}, see: http://www.regular-expressions.info/repeat.html