使用下面的函数,我试图通过查看设置为开始和结束的2个字符串变量来检索数字1003567400。
以下是数据:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app='app' ng-controller='ctrl'>
<input type='text' ng-model='searchText' />
<ul>
<li ng-repeat='customer in customers | searchFilter: searchText'>{{customer | json}}</li>
</ul>
</div>
以下是代码:
data = ('(ID: 1003567400) on local');
错误是:
var start = "ID:";
var end = ") on Local";
var testRE = data.match(start + "(.*)" + end);
console.log(testRE[1]);
如何解决此问题?
答案 0 :(得分:0)
data = ('(ID: 1003567400) on local');
console.log(data.match(/\(ID: (.*)\) on local/));
&#13;
您需要的是:https://regex101.com/r/qtckPB/1
你的正则表达式将是:\(ID: (.*)\) on local
data.match(/\(ID: (.*)\) on local/);
会返回您的值
答案 1 :(得分:0)
var start =&#34;(ID:&#34 ;;而不是var start =&#34; ID:&#34 ;;