Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何基于此特定场景在javascript中拆分字符串_Javascript_Regex_String - Fatal编程技术网

如何基于此特定场景在javascript中拆分字符串

如何基于此特定场景在javascript中拆分字符串,javascript,regex,string,Javascript,Regex,String,我有一个简单的名称、UserId和TaxId连接字符串 "Tester-N-U Academic Development Center-[10703]-[27-2008258]" 怎么可能?将其分解为字符串数组,以便在数组[0]中为'Tester-N-U学术发展中心',在数组[1]中为10703,在数组[2]中为27-2008258 这是我试过的 const input = $scope.Name_UserId_TaxID; const output = input.match(/[^[\]]

我有一个简单的名称、UserId和TaxId连接字符串

"Tester-N-U Academic Development Center-[10703]-[27-2008258]"
怎么可能?将其分解为字符串数组,以便在
数组[0]
中为
'Tester-N-U学术发展中心'
,在
数组[1]
中为
10703
,在
数组[2]
中为
27-2008258

这是我试过的

const input = $scope.Name_UserId_TaxID;
const output = input.match(/[^[\]]+(?=\])/g);
const splitProviderName = $scope.selectedValue.Name_UserId_TaxID.split('-', 1);
$scope.selectedProviderName = splitProviderName[0];
$scope.selectedProviderID = output[0];
$scope.selectedTaxID = output[1];
但这里的问题是,我只得到了Tester这个词,我希望Tester-N-U学术发展中心可以使用

var s=“Tester-N-U学术发展中心-[10703]-[27-2008258]”;
变量rx=/-\[([^\][]*)]/;
log(s.split(rx.filter)(布尔值))您可以使用

var s=“Tester-N-U学术发展中心-[10703]-[27-2008258]”;
变量rx=/-\[([^\][]*)]/;

log(s.split(rx.filter)(布尔值))您可以基于lookahead regex使用此匹配:

var str='Tester-N-U学术发展中心-[10703]-[27-2008258];

var arr=str.match(/(?您可以基于lookahead regex使用此匹配:

var str='Tester-N-U学术发展中心-[10703]-[27-2008258];


var arr=str.match(/(?您可以使用正则表达式,但最好的解决方案是更改字符串格式以单独提供值。在问题中更新了要使用的分隔符?请尝试
input.match(/(.-)-\[(.*)\]-\[(.*)\]/)
“Tester-N-U学术发展中心-[10703]-[27-2008258]”。替换(/]/g.)).split(“-[”)
您可以使用正则表达式,但最好的解决方案是更改字符串格式以单独提供值。在问题中更新了要使用什么分隔符?请尝试
input.match(/(.-)-\[(.*)\]-\[(.*)\]/)
“Tester-N-U学术发展中心-[10703]-[27-2008258]”。替换(/]/g.)。split(“-[”)
所需的jQuery在哪里?:-dw所需的jQuery在哪里?:-df对于正则表达式,您可以单击
运行代码片段
以查看实时演示。我怀疑您运行的是一个可能不支持查找的旧Javascript正则表达式引擎。您可以尝试:
/[\d-]+(?=\])作为正则表达式吗?(?=-\[)/
尝试放置数组[1]未定义此作品谢谢你如果名称是这样怎么办“;
使用了
~
作为分隔符,但我想排除userId和taxid中的括号,用于正则表达式。您可以单击
运行代码片段查看实时演示。我怀疑您运行的是一个可能不支持lookbehind的旧Javascript正则表达式引擎。您可以尝试:
/[\d-]+(?=\])\124^.+(?=-\[)/
作为正则表达式?尝试将数组[1]放在未定义的位置这项工作非常感谢如果名称是这样的话会怎么样
'Tester-N-U学术发展中心~[10703]~[27-2008258];
使用
~
作为分隔符,但我想排除userId和TaxId的括号