I am writing a function which is used to replace the class of div in certain conditions, for example,
- condition A - the div class is e_new_hazard_frame_2_1_4_7, I want to replace the 2 to 1, outcome should be like this - e_new_hazard_frame_1_1_4_7
- condition B - the div class is the same with above, I want to replace the 1 to 4, outcome should be like this - e_new_hazard_frame_2_4_4_7
- condition C - the div class is the same with above, I want to replace the 4 to 6, outcome should be like this - e_new_hazard_frame_2_1_6_7
- condition D - the div class is the same with above, I want to replace the 7 to 3, outcome should be like this - e_new_hazard_frame_2_1_4_3
these 4 numbers might be the same, like 1_1_1_1, my demo coding is like var str = 'e_new_hazard_frame_2_1'; str = str.replace(/_[_0-9]*)$/,'1');
it seems not correct can anyone teach me how to do it? thank you so much!