2

Filtering a data in angular with regex expression but doesnot get any output i am filtering data by following way: "trying to do exact match"

$scope.filteredEntries = filterFilter($scope.data, {path:'^/$'})

And $scope.data has following

$scope.data = [{'id':1,'Name':'abc','path':'/'},
              {'id':2,'Name':'def','path':'/'},
              {'id':3,'Name':'xyz','path':'/abc/'}]

expected data afterfilter

[{'id':1,'Name':'abc','path':'/'},
{'id':2,'Name':'def','path':'/'}]
0

1 Answer 1

1

Regular expressions are not supported like this, because it would be hard for framework to distinguish it from actual string '^/$'.

If you want exact match you can provide a comparator parameter true:

$scope.filteredEntries = filterFilter($scope.data, {path: '/'}, true);

Demo 1: http://plnkr.co/edit/WwpToPlb7j3JakGPVyFx?p=preview

Another options is to use a function to filter objects:

$scope.filteredEntries = filterFilter($scope.data, function(obj) {
    return /^\/$/.test(obj.path);
});

Note, that regular expression should be ^\/$, you need to escape / character. However for this specific task using regular expressions is overkill, you probably should go with the first option.

Demo 2: http://plnkr.co/edit/dqiOP2lkBx1OazwsSlw7?p=preview

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.