4
How do I filter the records of a Array
using the search terms separated by space ?
Example:
I have a Array
String with the following records.
- bottle opener
- box with blue padlock
- Brass padlock 30mm c/03 keys
- 100mm screwdriver
- lock lock set c/02 keys
- washcloth
- garden faucet
In the filter field the user type only chav, this search should return only the records.
- Brass padlock 30mm c/03 keys
- lock lock set c/02 keys
To try to solve this problem a function was created with a for
to read record by record of the Array
. For each record I tried using the regular expression "(Cade|chav)" it filters the following products;
- box with blue padlock
- Brass padlock 30mm c/03 keys yellow
- 100mm screwdriver
- lock lock set c/02 keys
However items in bold should not appear.
Another thing that should be taken into account the user can type only "padlock", or "Cad brass keys", or "blue" or with one or more words in the filter , until then I know I will have to mount the expression dynamically as "(Cade|chav)" or "(Cad|brass|keys)" or "(Azu)" etc.
If there is another way to solve this problem in java without using the regular expression it will also come.
At first I’d say you’d have to make a
if(match)
for every word present in the filter. Basically it would beif(match("cade") && match("chav")
.– Luis Henrique