mengo Posted November 21, 2014 Share Posted November 21, 2014 I saw an example when i was learning pcre recently. It is in dot chapter and its address is at http://php.net/manual/en/regexp.reference.dot.php. The codes like this: Consider, preg_match_all("/<img.*>/", $htmlfile, $match); preg_match_all("/(*ANY)<img.*>/", $htmlfile, $match); Now, any character that could possibly be seen as a newline will be interpreted as a newline by the PCRE. My question is "Does the dot character in pattern preg_match_all("/(*ANY)<img.*>/", $htmlfile, $match) really match newline?" I have thought quite some time but still don't know why. Can anyone help solve this question for me? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/292616-ask-for-a-simple-regexp-question/ Share on other sites More sharing options...
.josh Posted November 23, 2014 Share Posted November 23, 2014 That's what the manual entry says, and it seems to say that clearly. . are you looking for confirmation that the manual is right, or am I missing what you're really asking? Quote Link to comment https://forums.phpfreaks.com/topic/292616-ask-for-a-simple-regexp-question/#findComment-1497393 Share on other sites More sharing options...
mengo Posted November 24, 2014 Author Share Posted November 24, 2014 i just didn't understand a pattern like this "/(*ANY)<img.*>/", and it seems the use of character sequence "(*ANY)" has never appeared before. What is the meaning of "(*ANY)" here? Or does it should be seen as a pcre option like what the document tells? But when i use a string to match this pattern in the way like this, it seems it can't match $htmlfile: $htmlfile = "<img src='1.jpg'/>"; preg_match_all("/(*ANY)<img.*>/", $htmlfile, $matches); print_r($matches); How should i understand "(*ANY)" here? It seems pcre doesn't have this kind of use. Quote Link to comment https://forums.phpfreaks.com/topic/292616-ask-for-a-simple-regexp-question/#findComment-1497455 Share on other sites More sharing options...
Solution Ch0cu3r Posted November 24, 2014 Solution Share Posted November 24, 2014 It is do with how newlines are matched. The various options are explained here under the heading Newline/linebreak options The alternative is to apply the s pattern modifier. Quote Link to comment https://forums.phpfreaks.com/topic/292616-ask-for-a-simple-regexp-question/#findComment-1497480 Share on other sites More sharing options...
mengo Posted November 24, 2014 Author Share Posted November 24, 2014 Really thanks Ch0cu3r! I think i have figured out what the document means. In fact, the first pattern sometimes still can match multiple lines if the newline character is "\r", but the default newline character in Windows is "\n", the result is it can matches multiple lines in case "\r" is used but not in case of "\n" . While, the second pattern in case "(*ANY)" is included doesn't match multiple lines again no matter which condition it is, because either "\r" or "\n" will be seen as a newline/linebreak! It seems once in a while there will be one or two places let me headache. So appreciate for your suggestions! Quote Link to comment https://forums.phpfreaks.com/topic/292616-ask-for-a-simple-regexp-question/#findComment-1497492 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.