I use Rubular to test my regular expressions, when I need them. I am having a bit of trouble crafting an expression that will work for me. For reference, I am trying to match multiple substrings in any order. My problem, however, is that I cannot get the dot (
.) character to match newline characters.
I learned here that you can merge in options at the beginning of an expression using
(?[options]), so I assumed
(?m) would help me here. However, it does not seem to work:
Pattern keyword = Pattern.compile('(?mi)(?=.*\\bjack\\b)(?=.*\\bjill\\b)'); system.debug(keyword.pattern()); //(?mi)(?=.*\bjack\b)(?=.*\bjill\b) system.assert(keyword.matcher('jack n jill').find(); // works system.assert(keyword.matcher('jill n jack').find(); // works system.assert(keyword.matcher('Jack n Jill').find(); // works system.assert(keyword.matcher('jack \n jill').find(); // fail
However, it seems to me that this approach should work.