Ignore punctuations in searchbox filter


#1

I wrote a search filter for an ionic project below. It works fine but for the fact that it does not ignore punctuations.

So if the item i am searching for has a comma and I miss the comma in my query, I won’t find it. Is there a way for me to tell the filter to ignore commas and maybe even other punctuations as well?

See a few snippets of my example below:

<input class="search-bar" type="search" placeholder="Search" ng-model="data.searchQuery">
<ion-list>
  <ion-item  collection-repeat="hymn in hymns | filter: data.searchQuery">
    <h2><b>{{hymn.number}}. </b>{{hymn.title}}</h2>
  </ion-item>
</ion-list>

Javascript

var hymns = [
{
    "body": "I've written a body, it has punctuation too;\n",
    "number": 1,
    "title": "This Title, has a comma! and puctuations"
}, ...

#2

Yes, custom filters might be of help- its a mechanism to basically use your own logic. In your custom filter, you could remove punctuations from your hymns array while searching.