I need to split a string into a nested array something like this. Small subset of the actual data
- There is no fixed size, code could be
aaa100
andbbbbbbbb100
- No fixed char to split on
A similar problem is with converting file path to array but I dont have anything like /
to split on.
Use case:
Product import with a few thousand products. Each product code is made up with something like the following:
xxx product type
yyy size
zzz colour
So you have codes like xxxx
, xxxxyy
, xxxxzz
or xxxxyyzz
.
AAA100B // product type AAA with size 100 and colour blue
AAA200B // product type AAA with size 200 and colour blue
AAA100G // product type AAA with size 100 and colour green
BBB100B // product type BBB with size 100 and colour blue
Some do not have colour, others don't have size. Possible that some will not have 'matches' and just be a lone code.
Edit
The last char (or two) is normally a colour. Colours can be any of the following. (Colour code will never anywhere except the end of the string)
BK, GY
B, G, O, P, R, S
numbers are assumed to be the size, if the number is in the form 00-00
its lenght/width, else its a single size 00
Edit
Rough start to the problem, virtually there (expand and merge are part of the framework so just hacked them in there) http://codepad.viper-7.com/Wp19g2