Outils pour utilisateurs

Outils du site


web:php:regex:example

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
web:php:regex:example [le 10/10/2013 à 13:29] Yoskoweb:php:regex:example [le 17/02/2015 à 16:47] (Version actuelle) Yosko
Ligne 1: Ligne 1:
 ====== Exemples de regex en vrac ====== ====== Exemples de regex en vrac ======
  
-    // 1- remove recursively the content of for (), [] and {} +Quelques exemples d'expressions régulières utilisées en PHP :
-    // 2- removes escaped and " +
-    // 3- removes content betweend '' and "" (no recursion needed) +
-    $embracerPattern = "/\[([^\[\]]++|(?R))*+\]|\(([^\(\)]++|(?R))*+\)|{([^{}]++|(?R))*+}/"; +
-    $escapedQuotePattern = "/\\\\'|\\\\\"/"; +
-    $quotedStringPattern = "/'([^']++)*+'|\"([^\"]++)*+\"/";+
  
 +<code php>
 +// 1- remove recursively the content of for (), [] and {}
 +// 2- removes escaped ' and "
 +// 3- removes content betweend '' and "" (no recursion needed)
 +$embracerPattern = "/\[([^\[\]]++|(?R))*+\]|\(([^\(\)]++|(?R))*+\)|{([^{}]++|(?R))*+}/";
 +$escapedQuotePattern = "/\\\\'|\\\\\"/";
 +$quotedStringPattern = "/'([^']++)*+'|\"([^\"]++)*+\"/";
  
-    //replace escaped quotes with html entities +//replace escaped quotes with html entities 
-    $escapedQuotePattern = "/\\\\'/"; +$escapedQuotePattern = "/\\\\'/"; 
-    $call['code'] = preg_replace($escapedQuotePattern, '&#092;&#apos;', $call['code']); +$call['code'] = preg_replace($escapedQuotePattern, '&#092;&#apos;', $call['code']); 
-    $escapedQuotePattern = "/\\\\\"/"; +$escapedQuotePattern = "/\\\\\"/"; 
-    $call['code'] = preg_replace($escapedQuotePattern, '&#092;&#quot;', $call['code']); +$call['code'] = preg_replace($escapedQuotePattern, '&#092;&#quot;', $call['code']); 
-     + 
-    //replace commas between remaining (double) quotes with html entities +//replace commas between remaining (double) quotes with html entities 
-    $quotedStringPattern = "/'([^']++)*+'|\"([^\"]++)*+\"/"; +$quotedStringPattern = "/'([^']++)*+'|\"([^\"]++)*+\"/"; 
-    $call['code'] = preg_replace_callback( +$call['code'] = preg_replace_callback( 
-        $quotedStringPattern, +    $quotedStringPattern, 
-        function ($matches) { +    function ($matches) { 
-            return str_replace(',','&#044;',$matches[0]); +        return str_replace(',','&#044;',$matches[0]); 
-        }, +    }, 
-        $call['code'+    $call['code'
-    ); +); 
-     + 
-    //replace commas between parentheses, braces or brackets +//replace commas between parentheses, braces or brackets 
-    $embracerPattern = "/\[([^\[\]]++|(?R))*+\]|\(([^\(\)]++|(?R))*+\)|{([^{}]++|(?R))*+}/"; +$embracerPattern = "/\[([^\[\]]++|(?R))*+\]|\(([^\(\)]++|(?R))*+\)|{([^{}]++|(?R))*+}/"; 
-    $call['code'] = preg_replace($embracerPattern, '', $call['code']); +$call['code'] = preg_replace($embracerPattern, '', $call['code']); 
-     + 
-    //get the list of given parameters +//get the list of given parameters 
-    $results = preg_split('/,/', $call['code']);+$results = preg_split('/,/', $call['code']); 
 +</code>
web/php/regex/example.1381411760.txt.gz · Dernière modification : le 10/10/2013 à 13:29 de Yosko