Skip to content

Instantly share code, notes, and snippets.

@hkwid
Created January 7, 2016 14:25
Show Gist options
  • Select an option

  • Save hkwid/8b86d9b61f6ca5f6fccd to your computer and use it in GitHub Desktop.

Select an option

Save hkwid/8b86d9b61f6ca5f6fccd to your computer and use it in GitHub Desktop.
angularjs/regexFilter.js
angular.module('app')
.filter('regex', function() {
return function(input, field, regex) {
var pattern = new RegExp(regex);
var out = [];
for (var i = 0; i < input.length; i++){
if(pattern.test(input[i][field]))
out.push(input[i]);
}
return out;
};
});
@hkwid
Copy link
Copy Markdown
Author

hkwid commented Jan 7, 2016

{{[{'name': 'AngularJS'}, {'name': 'Backbone.js'}, {'name': 'VIEWERJS'}] | regex:'name':/A.*/}}

// results
{'name': 'AngularJS'}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment