删除“/&引用;来自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哦,我明白了,再次感谢。谢谢,很好的解决方案。