I have a list with the following keywords:
["mark", "anthony", "joseph smith", "michael",...]
I want to create a regex delimited by a |
so that I have something like:
mark|anthony|joseph smith|michael
I'm doing this like...
StringJoiner regex = new StringJoiner("|");
words.forEach(regex::add);
String matcher = regex.toString();
However there is an issue when I use this approach. If I have the following strings I want to match on:
"josephsmith is unique"
"joseph smith is unique"
I want both scenarios to match. What can I add to my code to ignore the whitespace?
I was thinking to maybe use replace(" ", ...)
on every keyword to replace the spaces with some sort of regex but I'm not sure how that would work with escaping characters.