sumitchawla / angularjs-filters

A library of common AngularJS filters.
https://www.npmjs.org/package/angularjs-filters
36 stars 7 forks source link

Regex Pattern Syntax Token Error #3

Open thomasjrivera opened 9 years ago

thomasjrivera commented 9 years ago

I am trying to use the filter my app but getting syntax errors. Its not liking passing a regex pattern of any kind. Its only working with a string replace.

This works {{ model.photos[1].caption | string.replace:'Mandatory':'' }}

Not working {{ model.photos[1].caption | string.replace:/Mandatory/g:'' }}

Getting unexpected token and Mandatory

sumitchawla commented 9 years ago

Thanks Thomas. I have fixed the error, and changed the usage pattern for regex. Please review the doc. If your use case is still broken i would request you to please make a change and send a pull request.

OddEssay commented 9 years ago

I'm not sure this fixed was propagated out to bower correctly - I just started using the filters using 'bower install angularjs-filters' and hit this exact problem.

thomasjrivera commented 9 years ago

I could not get it to work. I really just needed the regex replace so I just created by own like this.

.filter("regexReplace", function() { // register new filter

return function(input, searchRegex, replaceRegex) { // filter arguments

    return input.replace(RegExp(searchRegex), replaceRegex); // implementation

};

})

Perhaps the code library could be updated to use this.