Created
October 5, 2022 18:36
-
-
Save joeypy/8883c80d75cccc6400984b3cdbd80153 to your computer and use it in GitHub Desktop.
Advanced searching for JS with regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Code to make match with any character present in the input o query in this case | |
const values = ['Belgium', 'Brest', 'Britian'] | |
const query = 'Be' | |
// /.*b.*e.*/ | |
const re = RegExp(`.*${query.toLowerCase().split('').join('.*')}.*`) | |
// [ 'Belgium', 'Brest' ] | |
const matches = values.filter(v => v.toLowerCase().match(re)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment