如何在javascript中查找字符串中的特殊字符并存储在数组中
字符串示例如何在javascript中查找字符串中的特殊字符并存储在数组中,javascript,Javascript,字符串示例 "/city=<A>/state=<B>/sub_div=<C>/type=pos/div=<D>/cli_name=Cstate<E>/<F>/<G>" “/city=/state=/sub\u div=/type=pos/div=/cli\u name=Cstate/” 字符出现的形式有A、B、C和。。。。是变量,计数不是固定的 如何确定数组中存储了多少个变量使用正则表达式查找所有匹配项。 使
"/city=<A>/state=<B>/sub_div=<C>/type=pos/div=<D>/cli_name=Cstate<E>/<F>/<G>"
“/city=/state=/sub\u div=/type=pos/div=/cli\u name=Cstate/”
字符出现的形式有A、B、C和。。。。是变量,计数不是固定的
如何确定数组中存储了多少个变量使用正则表达式查找所有匹配项。 使用while循环,您可以迭代多个匹配项并将它们推送到一个数组中。试试这个
var String = "/city=<A>/state=<B>/sub_div=<C>/type=pos/div=<D>/cli_name=Cstate<E>/<F>/<G>";
var myRegexp = /\<.\>/gm;
var matches = [];
var match = myRegexp.exec(String);
while (match != null) {
matches.push(match[0])
match = myRegexp.exec(String);
}
console.log(matches)
var String=“/city=/state=/sub_div=/type=pos/div=/cli_name=Cstate/”;
var myRegexp=/\/gm;
var匹配=[];
var match=myRegexp.exec(字符串);
while(匹配!=null){
匹配。推送(匹配[0])
match=myRegexp.exec(字符串);
}
console.log(匹配项)
使用正则表达式查找所有匹配项。
使用while循环,您可以迭代多个匹配项并将它们推送到一个数组中。试试这个
var String = "/city=<A>/state=<B>/sub_div=<C>/type=pos/div=<D>/cli_name=Cstate<E>/<F>/<G>";
var myRegexp = /\<.\>/gm;
var matches = [];
var match = myRegexp.exec(String);
while (match != null) {
matches.push(match[0])
match = myRegexp.exec(String);
}
console.log(matches)
var String=“/city=/state=/sub_div=/type=pos/div=/cli_name=Cstate/”;
var myRegexp=/\/gm;
var匹配=[];
var match=myRegexp.exec(字符串);
while(匹配!=null){
匹配。推送(匹配[0])
match=myRegexp.exec(字符串);
}
console.log(匹配项)
请查看下面有助于解决问题的代码。它可以找到任何非单词字符并创建非单词数组
let str=“/city=/state=/sub_div=/type=pos/div=/cli_name=Cstate/”;
设arrStr=str.split(“”);
var strRegExp=/\W/g;
设arrNonWord=[];
arrStr.forEach(函数(str){
var结果=str.match(strRegExp);
如果(结果)
arrNonWord.push(结果[0]);
});
控制台日志(arrnword)代码>请查看下面有助于解决问题的代码。它可以找到任何非单词字符并创建非单词数组
let str=“/city=/state=/sub_div=/type=pos/div=/cli_name=Cstate/”;
设arrStr=str.split(“”);
var strRegExp=/\W/g;
设arrNonWord=[];
arrStr.forEach(函数(str){
var结果=str.match(strRegExp);
如果(结果)
arrNonWord.push(结果[0]);
});
控制台日志(arrnword)代码>您是否有一个示例,想要的输出和您尝试过的内容?您是在寻找对象还是数组?你试过什么吗?你有没有一个例子,想要的输出和你试过的东西?你是在寻找对象还是数组?你试过什么吗?@ShivajiWatekar随时。。如果它真的对你有帮助,请将其标记为正确答案。@ShivajiWatekar随时。。如果它真的对你有帮助,请把它标记为正确答案。