I have an input field where users can search a database for a certain name. The database contains names such as "Doe, John".

If a user searches for "john" I think it's easy to implement. However, if he or she searches for "john Doe" I would like to implement the logic search for john or search for doe. 

With RegEx I am completely lost. Is something like this even possible? However, with JS I would at least be able to consider this algorithm:

* Split the input on a whitespace and create to arrays
* Remove special characters
* Filter the JSON object retrieved from the database
* check, whether item includes the cleansed string-arrays

As for the JS-functions I tried something (in vain):

```
        let search = 'John Doe' //user input
        let data = ['Doe, John', 'Bean, Mister'] //data from database
        let split = search.split(" ") //split the whitespace into two arrays
        split = split.map(item => { return item.replace(/[^\w\s]+/gi, '')}) //remove dots, commas etc.
        let result = data.filter(item => { //filter each item from the data... 
            split.forEach(element => {
            let found = item.match(new RegExp(element, "i")) // so here I get matches, but how can I move them up the let the filter method return true?
            return found.length
            }).length>0

        })
        console.log(result)

```

Thanks to Taplars comment, I have used a map-method instead of a forEach:

```
let data = ['Doe, John', 'Bean, Mister']
    let split = search.split(" ")
    split = split.map(item => { return item.replace(/[^\w\s]+/gi, '')})
    let result = data.filter(item => {
      let filtered =   split.map(element => { 
            let ret = item.match(new RegExp(element, "i"))
            return ret
        })
      console.log(item,filtered) //now I have two arrays, one with something meaningful and one with [null,null]. How can I remove empty arrays?
      return filtered.length>0 
    })
    console.log(result)

```