Hi,

This script:

<?
        $line = "Use operator m// for matching strings";
        $pattern = "m//";

        if(preg_match("/$pattern/", $line, $match)) {
                print $match[0]."\n";
        }
?>

outputs the following error:

<br />
<b>Warning</b>:  Unknown modifier '/' in <b>/home/michael/bug.php</b> on 
line <b>5</b><br />


I thought it should find the match "m//" ...

Can you say, why search of the ending delimiter in a pattern cannot
be performed in a simple way, as you can see in the attached patch ?

Thanks.
--- ext/pcre/php_pcre.c.orig    2004-07-11 19:10:25.000000000 +0300
+++ ext/pcre/php_pcre.c 2004-07-11 20:16:32.000000000 +0300
@@ -180,41 +180,17 @@
                delimiter = pp[5];
        end_delimiter = delimiter;
 
-       if (start_delimiter == end_delimiter) {
-               /* We need to iterate through the pattern, searching for the ending 
delimiter,
-                  but skipping the backslashed delimiters.  If the ending delimiter 
is not
-                  found, display a warning. */
-               pp = p;
-               while (*pp != 0) {
-                       if (*pp == '\\' && pp[1] != 0) pp++;
-                       else if (*pp == delimiter)
-                               break;
-                       pp++;
-               }
-               if (*pp == 0) {
-                       php_error_docref(NULL TSRMLS_CC,E_WARNING, "No ending 
delimiter '%c' found", delimiter);
-                       return NULL;
-               }
-       } else {
-               /* We iterate through the pattern, searching for the matching ending
-                * delimiter. For each matching starting delimiter, we increment 
nesting
-                * level, and decrement it for each matching ending delimiter. If we
-                * reach the end of the pattern without matching, display a warning.
-                */
-               int brackets = 1;       /* brackets nesting level */
-               pp = p;
-               while (*pp != 0) {
-                       if (*pp == '\\' && pp[1] != 0) pp++;
-                       else if (*pp == end_delimiter && --brackets <= 0)
-                               break;
-                       else if (*pp == start_delimiter)
-                               brackets++;
-                       pp++;
-               }
-               if (*pp == 0) {
-                       php_error_docref(NULL TSRMLS_CC,E_WARNING, "No ending matching 
delimiter '%c' found", end_delimiter);
-                       return NULL;
+       /* Search for the ending delimiter iterating from the end of the pattern */
+       pp = p + strlen(p) -1;
+       while (pp >= p) {
+               if(*pp == end_delimiter) {
+                       break;
                }
+               pp--;
+       }
+       if (pp < p) {
+               php_error_docref(NULL TSRMLS_CC,E_WARNING, "No ending delimiter '%c' 
found", delimiter);
+               return NULL;
        }
        
        /* Make a copy of the actual pattern. */
-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to