Jump to content

Ask for a simple regexp question!


mengo

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/292616-ask-for-a-simple-regexp-question/
Share on other sites

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.

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.