Skip to content

Instantly share code, notes, and snippets.

@LukyVj
Last active August 24, 2021 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LukyVj/a632803b7ba6268e51edcfa347a09ac2 to your computer and use it in GitHub Desktop.
Save LukyVj/a632803b7ba6268e51edcfa347a09ac2 to your computer and use it in GitHub Desktop.
Nothing to see here officer
function getQueryPattern(query, flags = "i") {
const pattern = new RegExp(
`(${query
.trim() // Trim leading and ending whitespace
.toLowerCase() // convert to lower case
.split(" ") // Split on spaces for multiple commands
.map((token) => `^${token}`) // Map over the resulting array and create Regex_
.join("|")})`, // Join those expressions with an OR |
flags
);\n
return pattern;
}
\n
export default function App() { /* ... */ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment