<a href="link">[BIOL 107 Section 1] Concepts in Biology</a></td>
<a href="link">[CENG 230 Section 7] Introduction to C Programming</a>
<a href="link">[CENG 230 All Sections] Introduction to C Programming</a></td>
以上示例是我的代码。
我正在尝试获取不包含所有的anchors
。我几乎尝试了所有东西,看了正则表达式文档,但我无法想出一些有用的东西。
答案 0 :(得分:0)
答案 1 :(得分:0)
请勿使用正则表达式解析HTML,请使用DOMDocument:
.controller('verifyOrgCtrl', ['$rootScope', '$scope', '$state', '$http', 'dataServices', 'globalService', function ($rootScope, $scope, $state, $http, dataServices, globalService) {
$rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
window.history.forward();
});
$scope.orgList = [];
dataServices.getOrgList().then(function (res) {
if (res.status) {
$scope.orgList = res.orgList;
} else {
$rootScope.serviceErrorMsg = res.error;
$state.go(res.redirectURL);
}
});
$scope.organization = {};
$scope.validateOrg = function (formName) {
$scope.formName = formName;
if ($scope.formName.$invalid) {
$scope.showErrorMsg = true;
return;
}
}
}])
<强>输出:强>
$html = '
<a href="link1">[BIOL 107 Section 1] Concepts in Biology</a>
<a href="link2">[CENG 230 Section 7] Introduction to C Programming</a>
<a href="link3">[CENG 230 All Sections] Introduction to C Programming</a>
';
$dom = new DOMDocument;
$dom->loadHTML($html);
$tags = $dom->getElementsByTagName('a');
$links = array();
$value = array();
foreach($tags as $a){
if (preg_match('/\ball\b/i', $a->nodeValue)) continue;
$links[] = $a->getAttribute('href');
$value[] = $a->nodeValue;
}
print_r($links);
print_r($value);