Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.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
删除“/&引用;来自regex angularjs_Angularjs_Regex - Fatal编程技术网

删除“/&引用;来自regex angularjs

删除“/&引用;来自regex angularjs,angularjs,regex,Angularjs,Regex,如果在字符串中找到/,我将使用正则表达式拆分字符串。查找字符串和拆分的代码是:- $scope.string = $scope.newStr; $scope.tokens = $scope.string.match(/[^\/]+\/?|\//g); console.log($scope.tokens); 这给我的输出是[“1.1.1.2/”,“23”]我不希望/出现在1.1.1.2/中 另外,我想在新车型上单独显示23。 var-app=angular.module('plunker',[]

如果在字符串中找到
/
,我将使用正则表达式拆分字符串。查找字符串和拆分的代码是:-

$scope.string = $scope.newStr;
$scope.tokens = $scope.string.match(/[^\/]+\/?|\//g);
console.log($scope.tokens);
这给我的输出是
[“1.1.1.2/”,“23”]
我不希望
/
出现在
1.1.1.2/

另外,我想在新车型上单独显示23

var-app=angular.module('plunker',[]);
应用程序控制器('MainCtrl',函数($scope){
$scope.newStr='1.1.1.2/23';
$scope.string=$scope.newStr;
$scope.tokens=$scope.string.split(“/”)

对于(让我=0;我只是想提取除
/
以外的1+字符块,或者用
/
拆分。实际输入字符串是什么?@WiktorStribiżew感谢它的工作,但是我如何将它们绑定到两个不同的模型中?我的输出现在是
[“1.1.1.2”,“23”]
@TimBiegeleisen实际输入字符串是
$scope.newStr
的值是
1.1.1.2/23
1.1.1.2
是网关,而
23
是mask@WiktorStribi哦,我明白了,再次感谢。谢谢,很好的解决方案。