Reputation: 605
Sample Data:
ID Name User
12 Test Same
14 Xyz Joe
15 Abc John
16 Def Bill
17 Ghi Donald
If a user searches for Abc or Joe, he should get that rows.
Regex:
'Abc|Joe'
Output:
14 Xyz Joe
15 Abc John
Now, if the user further searches for e, it should filter based on the previous output(2 rows retrieved), so I will just get 14 Xyz Joe . Is this possible using regex?
I am trying to have all this in one regex.
`'Abc|Joe and the second filter goes here (All in one regex)'`
Use case: The user selects checkboxes to set the filters he wants to apply on the data (All the data in the columns Name and User are available). He may then search again on the filtered result using a search textbox.
Upvotes: 1
Views: 5148
Reputation: 6511
For the 2 filters:
/^\d+\s+(?:Abc|Xyz|Def)\s+\S*(?:Jo|ill).*/mg;
If the user doesn't specify the second filter, you could just leave it empty as (?:)
.
I'm positive you could create these kind of expressions if you read a couple of minutes about regex syntax, so allow me to recommend:
Upvotes: 1
Reputation: 1212
((firstRegex)(?:.*(secondRegex)))|((secondRegex)(?:.*(firstRegex)))
((Abc|Xyz)(?:.*(Jo)))|((Jo)(?:.*(Abc|Xyz)))
we don't know which regex would before or after,so it have two case and we use |
combine these case.If have more search,suggest you write some code.
Upvotes: 1