How can i ignore accents searching in Angular 2 from array of string

692 views
Skip to first unread message

Belen Martin

unread,
Aug 17, 2018, 12:19:54 PM8/17/18
to Angular and AngularJS discussion

private _filter(value: string): string[] {
const filterValue = value.toLowerCase();
if (this.options !== undefined) {
return this.options.filter (option => option.toLowerCase().includes(filterValue));
}
}

this.option is an array of string like :

options[0]="Pepe Pérez Pérez"
options[1]="Rosa Martínez Sánchez"

And I want to filter like ignoring caps but with ignoring the accent too.

Can anyone help me?

Sander Elias

unread,
Aug 17, 2018, 11:43:30 PM8/17/18
to Angular and AngularJS discussion
Hi Belen,

Good question! I learned a few things :). For example, what you want to do is called accent folding. 

This will do it:
cont stringFolded = string.normalize('NFD').replace(/[\u0300-\u036f]/g, "");
 the normalize('NFD') will split out the accents in the string. when that is done the regex matches anything that's not a 'char' and removes it.
 hope this helps,

Regards
Sander

Belen Martin

unread,
Aug 20, 2018, 3:12:28 AM8/20/18
to ang...@googlegroups.com
Thx you very much :*

--
You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages