I have the following string:
MISSILE 010102 FUZES AGAINST 2 RNG= 0.0 T= 82.846
TERMINAL POSITION: X= -75933.67 Y= -4469.98 Z= 25000.09
LAUNCH POSITION: X= -127017.19 Y= -12934.89 Z= 25506.47 MODE CMD_GUIDED_DES_RDR
AVERAGE VELOCITY= 3375.35
TERMINAL VELOCITY= 2545.36
LAUNCHER POSITION: X= -113879.58 Y= -16624.14 Z= 24476.13
FPOLE= 39848.34
GUIDANCE TRACKBANK 1 HAS TRACK ON FUZEE SEEKERS CONTRIBUTING INFRA-RED
ENDGAME SEEKER: IR 1
A/C 2 IS KILLED AT TIME 82.907
MISSILE 010102 FUZES AGAINST 3 RNG= 0.0 T= 82.846
TERMINAL POSITION: X= -75933.67 Y= -4469.98 Z= 25000.09
LAUNCH POSITION: X= -127017.19 Y= -12934.89 Z= 25506.47 MODE CMD_GUIDED_DES_RDR
AVERAGE VELOCITY= 3375.35
TERMINAL VELOCITY= 2545.36
LAUNCHER POSITION: X= -113879.58 Y= -16624.14 Z= 24476.13
FPOLE= 39848.34
GUIDANCE TRACKBANK 1 HAS TRACK ON FUZEE SEEKERS CONTRIBUTING INFRA-RED
ENDGAME SEEKER: IR 1
A/C 3 IS KILLED AT TIME 82.907
NOTE: The above example has is how the strings would always be formatted. There may be many more than just these two, but they will always follow the above format.
I want to split this string on the "A/C 2 IS KILLED AT TIME 82.907" is killed part, but keep the delimiter.
My desired output for this example would be as follows:
['MISSILE 010102 FUZES AGAINST 2 RNG= 0.0 T= 82.846
TERMINAL POSITION: X= -75933.67 Y= -4469.98 Z= 25000.09
LAUNCH POSITION: X= -127017.19 Y= -12934.89 Z= 25506.47 MODE CMD_GUIDED_DES_RDR
AVERAGE VELOCITY= 3375.35
TERMINAL VELOCITY= 2545.36
LAUNCHER POSITION: X= -113879.58 Y= -16624.14 Z= 24476.13
FPOLE= 39848.34
GUIDANCE TRACKBANK 1 HAS TRACK ON FUZEE SEEKERS CONTRIBUTING INFRA-RED
ENDGAME SEEKER: IR 1
A/C 2 IS KILLED AT TIME 82.907', 'MISSILE 010102 FUZES AGAINST 3 RNG= 0.0 T= 82.846
TERMINAL POSITION: X= -75933.67 Y= -4469.98 Z= 25000.09
LAUNCH POSITION: X= -127017.19 Y= -12934.89 Z= 25506.47 MODE CMD_GUIDED_DES_RDR
AVERAGE VELOCITY= 3375.35
TERMINAL VELOCITY= 2545.36
LAUNCHER POSITION: X= -113879.58 Y= -16624.14 Z= 24476.13
FPOLE= 39848.34
GUIDANCE TRACKBANK 1 HAS TRACK ON FUZEE SEEKERS CONTRIBUTING INFRA-RED
ENDGAME SEEKER: IR 1
A/C 3 IS KILLED AT TIME 82.907']
I tried these regex patterns which are pretty close:
str.split(/[ ]+A\/C[ ]+[0-9]{1,2}[ ]+IS[ ]+KILLED[ ]+AT[ ]+TIME[ ]+[0-9]{0,4}\.[0-9]{0,4}/)
This gives me the text preceding the pattern, but of course the pattern matching text is removed. jsfiddle demo: https://jsfiddle.net/JordanCastillo/au7ontxf/1/
This one keeps the pattern, but it is a separate member of the array:
str.split(/([ ]+A\/C[ ]+[0-9]{1,2}[ ]+IS[ ]+KILLED[ ]+AT[ ]+TIME[ ]+[0-9]{0,4}\.[0-9]{0,4})/)
jsfiddle demo: http://jsfiddle.net/JordanCastillo/em7f1tqa/6/
After looking around, I found the following example:
https://stackoverflow.com/a/25221523/9861344
In the author's 4th example, he retains the delimiter on the text preceding it.
I tried replicating this, but as the comments indicate, it only works on single characters
https://jsfiddle.net/JordanCastillo/ot60azw1/1/