I have to identify lines from a CSV file that match a certain search criteria. The data in the CSV file looks somethin like this:
Wilbur Smith,Elephant Song,McMillain,1992,1
Wilbur Smith,Birds of Prey,McMillain,1992,1
George Orwell,Animal Farm,Secker & Warburg,1945,1
George Orwell,1984,Secker & Warburg,1949,1
The search criteria is like this:
Orwell,,,,
,Elephant,,,
The first line identifies 2 lines, the second 1 line. I'm currently reading the file as follows, but not using the criteria above.
br = new BufferedReader(new FileReader(csvFile));
while ((line = br.readLine()) != null) {
String[] dataItems = line.split(cvsSplitBy);
if (dataItems[0].contains(title) && dataItems[1].contains(author) && dataItems[2].contains(publisher)) {
bk[i++] = line;
if (bk.length > 4) {break;}
}
}
I am adding to a fixed size array. How can I use the criteria as a regular expression to identify a line?
contains()to see if a column value contains the given text, like you're doing now. No need for regex..contains()or similar methods to search instead of trying to use Regex. This problem isn't the right candidate for using regex IMO.