I have some text I am trying to replace a part of with regex in Angularjs.
The text will be in the format:
Name: Jane
Age: 66
Address: 31 Test Street
I would like to replace the part after Age: with 'REDACTED' (so 66 will not appear), so I have created this filter which to me seems like it should work:
angular.module('person')
.controller(controllerId, personControl)
.filter('ageFilter', function () {
return function (text) {
if (text)
return text.replace(/[\n\r].*Age: \s*([^\n\r]*)/, 'REDACTED');
return '';
}
});
The relevant part of the html:
<dd ng-bind-html="vm.model.PERSON_INFO | ageFilter"></dd>
The filter is hit but the text is never replaced. My regex works when I test on Regex test websites, so I think I may be doing something else wrong which I cannot see.
text.replace(/^(Age:[\t ]*).*/m, '$1REDACTED');suffice? See this regex demo. BTW, your regex does not work well.