I have a pretty long string(called 'my_string') without new lines included. I have been trying to use regexp in JavaScript to find specific words in 'my_string'. Below is the code description
my_string=`Type of reaction engine discharging a fast-moving jet that generates thrust by jet propulsion. While this broad definition can include rocket, water jet, and hybrid propulsion, the term jet engine typically refers to an internal combustion airbreathing jet engine such as a turbojet, turbofan, ramjet, or pulse jet.[1] In general, jet CP_COLOR_B[#240025: engines]CP_COLOR_E are internal combustion engines. jet engines typically feature a rotating air CP_COLOR_B[#254117: compressor]CP_COLOR_E powered by a turbine, with the leftover power providing thrust through the propelling nozzle—this CP_COLOR_B[#2424df: combined]CP_COLOR_E is known as the Brayton thermodynamic cycle.`;
var free_10_array = my_string.split("\n");
var free_10 = '';
for(var _10 in free_10_array){
free_10+=free_10_array[_10];
}
const my_patt = new RegExp("(CP_COLOR_B\\[.+\\]CP_COLOR_E)", "gi");
var result_array = my_string.match(my_patt);
console.log(result_array);
I am expecting the array result_array
to be a length of three(3) since there are only three(3) patterns(CP_COLOR_B[#240025: engines]CP_COLOR_E, CP_COLOR_B[#254117: compressor]CP_COLOR_E and CP_COLOR_B[#2424df: combined]CP_COLOR_E) I am aiming to find. Instead, I got an array of one element with other strings attached to only the first matched pattern.
I will love to have the result in this form, such as:
output=['CP_COLOR_B[#240025: engines]CP_COLOR_E','CP_COLOR_B[#254117: compressor]CP_COLOR_E','CP_COLOR_B[#2424df: combined]CP_COLOR_E']