Why the regex below not working for the text below
Regex:
(?=.*\berror\b)(?=.*\balarm\b).*
Text :
ns1.alarm.abc 
ns2.error.cdb
In other works how to do multiline regex match?
Why the regex below not working for the text below
Regex:
(?=.*\berror\b)(?=.*\balarm\b).*
Text :
ns1.alarm.abc 
ns2.error.cdb
In other works how to do multiline regex match?
 
    
     
    
    I think you are trying to find the strings containing either error or alarm and for that you can try the following:
Try this Regex:
(?=.*\b(?:error|alarm)\b).*
Explanation:
(?=.*\b(?:error|alarm)\b) - Positive lookahead for checking the presence of the words - error OR alarm.* - if the above condition is satisfied, match 0+ occurrences of all characters(except a newline character)Your regex (?=.*\berror\b)(?=.*\balarm\b).* does not work as it is trying to find both the words error and alarm in the same line/input string. So, you needed to put an OR condition as shown above.
Update:
To match both, use this.
(?=[\s\S]*\berror\b)(?=[\s\S]*\balarm\b)[\s\S]* as shown HERE
