I have a regular expression like the following: (Running on Oracle's regexp_like()
, despite the question isn't Oracle-specific)
abc|bcd|def|xyz
This basically matches a tags
field on database to see if tags
field contains abc
OR bcd
OR def
OR xyz
when user has input for the search query "abc bcd def xyz
".
The tags
field on the database holds keywords separated by spaces, e.g. "cdefg abcd xyz"
On Oracle, this would be something like:
select ... from ... where
regexp_like('abc|bcd|def|xyz', tags);
It works fine as it is, but I want to add an extra option for users to search for results that match all keywords. How should I change the regular expression so that it matches abc
AND bcd
AND def
AND xyz
?
Note: Because I won't know what exact keywords the user will enter, I can't pre-structure the query in the PL/SQL like this:
select ... from ... where
tags like '