I know one can use OR operator on regular expressions:
$str = "Here is a strawhat, some cranberry, and a strawberry!";
while($str =~ /(\bstraw\B|\Bberry\b)/g) {
print "Thanks for the $& !\n";
}
Is there a simple and short way other than a while loop to AND them instead of OR, so that the only match is “strawberry”?
In other words, I need to check if there exists a substring in a string that matches all of the given regular expressions.
If I’m understanding your question correctly, you can use lookahead assertions for this:
There are a couple of assumptions built into this construction:
.metacharacter to mean “any character except a newline”. You could turn this behavior back on with(?-s:...)as necessary.