我有以下名为 cityList 的数据数组:
var cityList = [
"Anaa, French Polynesia (AAA)",
"Arrabury, Australia (AAB)",
"Al Arish, Egypt (AAC)",
"Ad-Dabbah, Sudan (AAD)",
"Annaba, Algeria (AAE)",
"Apalachicola, United States (AAF)",
"Arapoti, Brazil (AAG)",
"Aachen, Germany (AAH)",
"Arraias, Brazil (AAI)",
"Awaradam, Suriname (AAJ)",
"Aranuka, Kiribati (AAK)",
"Aalborg, Denmark (AAL)"
];
我想首先搜索从字符串开头开始的城市名称。
接下来我要搜索字符串的代码部分:AAA、AAB、AAC 等...
我想将搜索模式应用为 javascript 正则表达式,首先应用到城市名称,然后应用到城市代码。
这是我的正则表达式:
// this regular expression used for search city name
var matcher = new RegExp("^" + re, "i");
// this regular expression used for search city code
var matcher = new RegExp("([(*)])" + re, "i");
如何将这两个正则表达式组合成一个按描述工作的正则表达式?