Regex: diferència entre les revisions
Salta a la navegació
Salta a la cerca
(Es crea la pàgina amb « /text/ Sensible a majuscules /text/i Insensible a majuscules [^>] Any character except > ? lazy search (as small as possible) :.+?: any amount of character bet...».) |
Cap resum de modificació |
||
(Hi ha una revisió intermèdia del mateix usuari que no es mostren) | |||
Línia 1: | Línia 1: | ||
/text/ Case sensible | |||
/text/ | /text/i Not Case sensible | ||
/text/i | |||
[^>] Any character except > | [^>] Any character except > | ||
Línia 9: | Línia 8: | ||
:[^:]: should be the same | :[^:]: should be the same | ||
() Exports data to $match[1], second () to $match[2] | () Exports data to $match[1], second () to $match[2] ...etc. | ||
$match[0] is everything | $match[0] is everything | ||
There are 11 characters with special meanings (have to be escaped with "\"): | |||
the opening square bracket [ | |||
the backslash \ | |||
the caret ^ | |||
the dollar sign $ | |||
the period or dot . | |||
the vertical bar or pipe symbol | | |||
the question mark ? | |||
the asterisk or star * | |||
the plus sign + | |||
the opening round bracket ( | |||
and the closing round bracket ) | |||
<pre> | <pre> | ||
Línia 32: | Línia 45: | ||
</pre> | </pre> | ||
Example taken form here: http://esa.espai.de/Logica_client-logica | Example taken form here: http://esa.espai.de/Logica_client-logica | ||
Nice reference guide here: http://www.regular-expressions.info/reference.html |
Revisió de 20:09, 16 gen 2013
/text/ Case sensible /text/i Not Case sensible
[^>] Any character except > ? lazy search (as small as possible) :.+?: any amount of character between : and : (but at least one) :.*?: any amount of character between : and : ("::" is ok) :[^:]: should be the same
() Exports data to $match[1], second () to $match[2] ...etc. $match[0] is everything
There are 11 characters with special meanings (have to be escaped with "\"):
the opening square bracket [ the backslash \ the caret ^ the dollar sign $ the period or dot . the vertical bar or pipe symbol | the question mark ? the asterisk or star * the plus sign + the opening round bracket ( and the closing round bracket )
preg_match_all('/\[(.*?) (.*?)\].*?: (.*?);.*?idle=(.*?)% user=(.*?)% system=(.*?)% iowait=(.*?)%/i', $text, $match); for ($i = 0; $i < count($match[1]); $i ++) { $file = "nagiossnap/" . $match[3][$i] . ".txt"; file_put_contents($file, $match[1][$i] . "\t" . $match[2][$i]. "\t" . $match[4][$i]. "\t" . $match[5][$i] . "\t" . $match[6][$i] . "\t" . $match[7][$i] . "\n", FILE_APPEND | LOCK_EX); print $match[1][$i]; print $match[2][$i]; print $match[3][$i]; print $match[4][$i]; print $match[5][$i]; print $match[6][$i]; print $match[7][$i]; (...)
Example taken form here: http://esa.espai.de/Logica_client-logica
Nice reference guide here: http://www.regular-expressions.info/reference.html