I was wondering if anyone could tell be whether it's possible to
instruct preg_match not to save subexpressions matches under 0, 1...n
keys when using named subexpressions; I.e instruct preg_named to
matched under their names only,
and not under their numbers. E.g. take the following example:
<pre style="width:10 0%;text-align:justify">
/^(?:(?:ftp|http )\:\/\/)?(?P<host>[^\/\:]*)(?:\:(?P<port >[0-9]{4}))?(?:(?P<pa th>\/(?:[~\%\w\.\-_]*\/)+)?(?P<file>[~\%\w\.\-_]+)(?:\?(?P<quer y>.*))?)?$/
</pre>
for the string
"http://groups.google.c om/group/comp.lang.php/post?hl=en&_don e=%2Fgroup%2Fco mp.lang.php%2Fb rowse_thread%2F thread%2Fa56103 941c7e5176%2F9b 7c8045d2841990% 3Fq%3Dregular+e xpressions+sub-expressions%26r num%3D1%26hl%3D en%26&"
generates the following matches:
Array
(
[0] =>
[host] => groups.google.c om
[1] => groups.google.c om
[port] =>
[2] =>
[path] => /group/comp.lang.php/
[3] => /group/comp.lang.php/
[file] => post
[4] => post
[query] =>
hl=en&_done=%2F group%2Fcomp.la ng.php%2Fbrowse _thread%2Fthrea d%2Fa56103941c7 e5176%2F9b7c804 5d2841990%3Fq%3 Dregular+expres sions+sub-expressions%26r num%3D1%26hl%3D en%26&
[5] =>
hl=en&_done=%2F group%2Fcomp.la ng.php%2Fbrowse _thread%2Fthrea d%2Fa56103941c7 e5176%2F9b7c804 5d2841990%3Fq%3 Dregular+expres sions+sub-expressions%26r num%3D1%26hl%3D en%26&
)
Notice that all subexpressions are saved twice in the array. Can this
be avoided?
instruct preg_match not to save subexpressions matches under 0, 1...n
keys when using named subexpressions; I.e instruct preg_named to
matched under their names only,
and not under their numbers. E.g. take the following example:
<pre style="width:10 0%;text-align:justify">
/^(?:(?:ftp|http )\:\/\/)?(?P<host>[^\/\:]*)(?:\:(?P<port >[0-9]{4}))?(?:(?P<pa th>\/(?:[~\%\w\.\-_]*\/)+)?(?P<file>[~\%\w\.\-_]+)(?:\?(?P<quer y>.*))?)?$/
</pre>
for the string
"http://groups.google.c om/group/comp.lang.php/post?hl=en&_don e=%2Fgroup%2Fco mp.lang.php%2Fb rowse_thread%2F thread%2Fa56103 941c7e5176%2F9b 7c8045d2841990% 3Fq%3Dregular+e xpressions+sub-expressions%26r num%3D1%26hl%3D en%26&"
generates the following matches:
Array
(
[0] =>
[host] => groups.google.c om
[1] => groups.google.c om
[port] =>
[2] =>
[path] => /group/comp.lang.php/
[3] => /group/comp.lang.php/
[file] => post
[4] => post
[query] =>
hl=en&_done=%2F group%2Fcomp.la ng.php%2Fbrowse _thread%2Fthrea d%2Fa56103941c7 e5176%2F9b7c804 5d2841990%3Fq%3 Dregular+expres sions+sub-expressions%26r num%3D1%26hl%3D en%26&
[5] =>
hl=en&_done=%2F group%2Fcomp.la ng.php%2Fbrowse _thread%2Fthrea d%2Fa56103941c7 e5176%2F9b7c804 5d2841990%3Fq%3 Dregular+expres sions+sub-expressions%26r num%3D1%26hl%3D en%26&
)
Notice that all subexpressions are saved twice in the array. Can this
be avoided?
Comment