I am having an array of phone numbers . I have also a search string. The search string is provided by the user. The search string can contain wild cards such as asterik(*) or question mark (?). I need a way to filter out elements from my phone number array .
The following is my phone number array.
let mobileNumbersArray = ["830456481", "831456481", "9886503103" ]
**Condition 1**
when search string is *
let searchString = "*"
expected result = ["830456481", "831456481", "9886503103"]
**Condition 2**
when search string is 83*
let searchString = "83*"
expected result = ["830456481", "831456481"]
**condition 3**
let searchString = "*456*"
expected result = ["830456481", "831456481"]
**condition 4**
exact search
let searchString = "9886503103"
expected result = ["9886503103"]
**condition 5**
exact search
let searchString = "83?4"
expected result = ["830456481", "831456481"]
how can i achieve searching a string on my phone number array and getting the result as an array in the cleanest way as possible.
appreciate any help
thank you .