function find_str_between(l, s_s, s_e){ let ls = l.split(s_s); if(ls.length > 1){ if(s_e){ let ls2 = ls[1].split(s_e); if(ls2.length > 1){ return ls2[0]; } else { return ''; } } else { return ls[1]; } } else { return ''; } } function find_ls_between(l, s_s, s_e){ let ls_r = []; let ls = l.split(s_s); for(let i = 1; i < ls.length; i++){ if(s_e){ let ls2 = ls[i].split(s_e); if(ls2.length > 1){ ls_r.push(ls2[0]); } else { ls_r.push(''); } } else { ls_r.push(ls[1]); } } return ls_r; } console.log(find_str_between("Hello World!", 'e', 'o')); console.log(find_ls_between("<td>1</td><td>2</td>", '<td>', '</td>'));
输出:
ll [ '1', '2' ]