Hello,
I'm a RegEx newbie and am struggling to understand some code that I've inherited. I was hoping someone could break this down for me to let me know what is going on here:
preg_replace('/(.*)(<\?\s*?include\s*?\(\s*[\'"].*?\/incs\/.*?[\'"]\s*\)[^>]+?\?>)(.*?)(<\/td>)(.*)/s','$1$2$4$5',$txt);
In addition to wondering what this does, my return string is always empty...shouldn't it return the original even if there isn't a match?
Thanks for all your help with this.
RegEx problem
Moderator: General Moderators
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: RegEx problem
I'll give it a try (simplified):regexnewbie wrote:Hello,
I'm a RegEx newbie and am struggling to understand some code that I've inherited. I was hoping someone could break this down for me to let me know what is going on here:
preg_replace('/(.*)(<\?\s*?include\s*?\(\s*[\'"].*?\/incs\/.*?[\'"]\s*\)[^>]+?\?>)(.*?)(<\/td>)(.*)/s','$1$2$4$5',$txt);
In addition to wondering what this does, my return string is always empty...shouldn't it return the original even if there isn't a match?
Thanks for all your help with this.
Code: Select all
/ just a starting delimiter to delimit the pattern
(.*) any number of any characters capture as backreference $1
(<\? followed by <? - start capturing as backreference $2
\s*? followed by any number of whitespace characters
include followed by the literal string "include"
\s*? followed by any number of whitespace characters
\( followed by a (
\s* followed by any number of whitespace characters
[\\'"] followed by 1 single or double quote
.*? followed by any number of any characters
\/ followed by /
incs followed by the literal string "incs"
\/ followed by /
.*? followed by any number of any characters
[\\'"] followed by 1 single or double quote
\s* followed by any number of whitespace characters
\) followed by a )
[^>]+ followed by 1 or more characters that are NOT a >
\?\?>) followed by ??> - end capturing as backreference $2
(.*?) followed by number of any characters capture as backreference $3
(<\/td>) followed by </td> capture as backreference $4
(.*) followed by any number of any characters capture as backreference $5
/ ending delimiter
s modifier to make the . match newline charactersCode: Select all
$txt = preg_replace('/(.*)(<\?\s*?include\s*?\(\s*[\'"].*?\/incs\/.*?[\'"]\s*\)[^>]+?\?>)(.*?)(<\/td>)(.*)/s','$1$2$4$5',$txt);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.