I have potential inputs that will come in from a read -e -p command in a bash script. For example, the user would type L50CA. Some other possibilites that the user could type in are: K117CB, K46CE2, or V9CE1.
I need to break up what was read in. I read in like this:
read -e -p "What first atom? " sel1
then I would like to make an array like this (but this will not separate):
arr1=($sel1)
But I need to separate the array so that
${arr1[0]} is equal to L
${arr1[1]} is equal to 50
and ${arr1[2]} is equal to CA
This separation has to work with the other possible user input formats like the ones listed above. Regex seems to be the way to do this. I can isolate the first two matches of the input with the following regular expressions: ^\D and \d*(?=\w)
I need help matching the third component and implementing it into an array. Alternatively, it is fine to to break up the user input into three new variables. Or we can place a space between each of the matches so L50CA is converted to L 50 CA because then arr1=($sel1) will work.
Thanks for your help.
K46CE2split into?K,46,CE2? OrK,46,CE,2?