import { Pipe , PipeTransform } from '@angular/core' ; @ Pipe ( { name : 'highlight' } ) export class HighlightPipe implements PipeTransform { transform ( text , search ) { if ( search . length > 0 ) { return this . Strip ( text ) . replace ( new RegExp ( `${ this . EscapeMatch ( search ) }` , 'gi' ) , ( match ) => { return `<span class="dropdown-item-highlight">${ match }</span>` ; } ) ; } else { return text ; } } EscapeMatch ( match ) { const entityMap = { '&' : '\\&' , '<' : '\\<' , '>' : '\\>' , '/' : '\\/' , '=' : '\\=' , '+' : '\\+' , '-' : '\\-' , '#' : '\\#' , '!' : '\\!' , '@' : '\\@' , '$' : '\\$' , '%' : '\\%' , '^' : '\\^' , '*' : '\\*' , '(' : '\\(' , ')' : '\\)' , } ; return String ( match ) . replace ( /[&<>"'`=+\/]/g , function ( s ) { return entityMap [ s ] ; } ) ; } Strip ( str_in = '' ) { return str_in . replace ( /<[^>]*>/g , '' ) ; } }