Home > Backend Development > PHP Tutorial > php中Warning: preg_match_all(): Compilation failed: lookbehind assertion

php中Warning: preg_match_all(): Compilation failed: lookbehind assertion

WBOY
Release: 2016-07-25 08:46:43
Original
2169 people have browsed it
Today when I was testing the code related to looking around in regular expressions, I found an error
The error message is as follows:
Warning: preg_match_all(): Compilation failed: lookbehind assertion is not fixed length at offset
The code is as follows:
  1. $str='
    info
    strong';
  2. preg_match_all('/(?<=<(w+)[ ^>]*>).*(?=)/',$str,$match);
  3. var_dump($match);
Copy the code
Execute the above code An error will be reported. After checking online, it is said that reverse lookaround in PHP (including reverse positive lookaround?<=exp, reverse negative lookaround?
Change the above code to:
  1. $str='
    info
    strong';
  2. preg_match_all('/(?<=< (w)>).*(?=)/',$str,$match);
  3. var_dump($match);
Copy code
But this can only match b Strong content in tags
Actually, you don’t need to look around to match, you can directly use grouping to capture the content. You just need to filter the returned results
  1. $str='
    info
    strong';
  2. preg_match_all('/(<(w+)[^>]*>)(.*)()/',$str,$match);
  3. print_r( $match[3]);//Array ( [0] => info [1] => strong )
Copy code




source:php.cn
Statement of this 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template