I have string with multiple newlines, each new line contains a new substring.
Here is an example of the string with 2 lines :
$x="Hello
World!
You can see Hello is in the first line and World! is in a newline.
Each substrings start and end with or without a newline(s)|space(s).
I want to match both lines.
My currunt code matched the second line and ignored the first.
if(preg_match_all("/^\n*\s*(Hello|World!)\s*$/i",$x,$m))
{print_r($m);}
Is there any way to fix this,so that both lines can be matched?
xindeed is a single string with two words separated by a newline. The alternation allows for only one of the words to match, and the anchors that tie the match to the start and end of the string are outside of the alternation, which means both must match for the regex to succeed - and that means that the string can only match if there is exactly one word in it . If you had used the/mmodifier, they would also have matched at the start/end of each new line, but that modifier isn't being used...