Jump to content

mengo

Members
  • Posts

    11
  • Joined

  • Last visited

mengo's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I don't know whether you have noticed that your pattern has many errors. Firstly, there is no need to use a subpattern, the outside pair of parentheses can completely be droped. Secondly, if you want to strip spaces next to '(' and ')', you need to use \s+ at both start and end sides, '[\s.]' is another mistake. At last, the content within '(' and ')', there is space in string '180 degrees' so a character represent white space also exists in character class, you can use either ' ' or '\s'. So the right pattern should like this '/\s+\([\w\s-]\)\s+/' or '/\s+\([\w -]\)\s+/'.
  2. of couse, it doesn't, because you missed a whitespace in '[\w-]'
  3. replace '[0-9-]+' with '[\w-]+', '[0-9-]' doesn't contain letter characters
  4. 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!
  5. 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.
  6. 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!
  7. yes,thanks for your advice! both of them!
  8. now it is clear! really thanks! may be i should spend some time studying pattern more carefully!
  9. thank you for your help! I found another weird problem,for example: $pattern = "/(1)(2)(3)(4)(5)(6)(7)((9)\3fgh/"; $subject = "1234567893fghijk"; preg_match_all($pattern, $subject, $matches); echo "<pre>"; print_r($matches); echo "</pre>"; echo chr(2); form \1 to \7, no matter whick back reference is used, there will always get not correct result! But when changed to \8 or \9, if there is a respondding matching substring in variable $subject,while it will get correct result. Where there is a difference between these two conditions?
  10. value of $pattern is not important ,it can also be replaced by "/(b)c(d)\2efgh/",i don't know why an error occurs when i try to edit the first subpattern,maybe this value is better. why "\2" can't reference the second subpattern "(d)"? thanks!
  11. hello,you all. there is a problem let me not understand.i have a few codes like this: $pattern = "/b©(d)\2efgh/"; $subject = "abcddefghijk"; preg_match_all($pattern, $subject, $matches); echo "<pre>"; print_r($matches); echo "</pre>"; i want to use var $pattern capture str "bcddefgh" in var $subject with "\2" back reference,but the result is not what i want,it ouputs nothing but an empty array. i think i did nothing wrong, in php manual, it says a backslash followed by a non-0 number can represent a back reference.but why it fails? is there something wrong with my codes or an error in php manual? is there some other problems in php.ini or somewhere else? help, thanks!!
×
×
  • 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.