分享至
var string = "An apple a day"; var test = "An"; var result = string.match(/^An/); console.log(result);
想請問如果string.match(/^An/)的An要改成用變數test搜尋,請問要怎麼改寫呢?
已邀請的邦友 {{ invite_list.length }}/5
var string = "An apple a day"; var search = "An"; var test = new RegExp("^"+search, "g"); var result = string.match(test); console.log(result);
選我正解
IT邦幫忙