How to match text like this using PHP regular expressions? ? My initial thoughts: Pattern: "/
[.\n]*?<\/tr>" (This is wrong) Ideas: "." can match For any non-newline characters, use the "[.\n]" combination to make it match all characters (including newlines), but there are unforeseen circumstances - tragedy, the result is nothing! After a lot of gnawing at the bones, I wrote another one Pattern: "/
(.|\n)*?<\/tr>" (This is possible) Replace "[ ]" is replaced with "()", and "|" is used to make an or selection, and that's it (I'm confused, why can't "[]" also be used as a selection method???) There is also an answer on the Internet: PATTEN: "/
.*?<\/tr>/is" (very concise and convenient, I agree with this method)
Postscript: Why is it that "[]" is also the selected method? ? ? ? If you know it, don’t forget to tell me... The . in
[] is equivalent to \., please read the regular description carefully.
Generally consider using the pattern modifier when it comes to line breaks. s
s (PCRE_DOTALL) If this modifier is set, the dot metacharacter in the pattern matches all characters, including newlines. Without this modifier, the dot metacharacter does not match newlines.
[] contains some ranges or combinations lzTry "/
[.]*?<\/tr>/is" and you will know, Also () Very powerful
For more articles related to regular expression analysis of PHP matching multiple lines, please pay attention to the PHP Chinese website!
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn