'Apply regular expression with different string array using Regex [closed]
I want to use different scenarios of the string matched and filter.
Ex:-
a = ['Rubico Fans Draw', 'David Rubico Fanch', 'Nikas Fans Farius']
I want out like this:-
'Rubico'
o/p:- ['Rubico Fans Draw', 'David Rubico Richad']
'Fan'
o/p:- ['Rubico Fans Draw', 'David Rubico Fanch', 'Nikas Fans Farius']
'Rubico Fans Draw'
o/p:- ['Rubico Fans Draw']
Solution 1:[1]
const items = ['Rubico Fans Draw', 'David Rubico Fanch', 'Nikas Fans Farius'];
const regex = /Rubico/;
const matchedItems = items.filter(item => item.search(regex) !== -1);
console.log(matchedItems);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Amir |
