So in etwa. Per Google findest du aber auch ausführlichere Erklärungen. Auch zu den anderen Methoden.
Beitrag editiert:
[…] Zu langsam…
Beitrag editiert:
[…] Zu langsam…
// Korrekt "s\"" "t\\" "u\\\"\\\\\\" // Inkorrekt "v\" "w\\\\\" "x\"\"
<?php
header("Content-Type: text/plain; charset=UTF-8");
define("REGEXP_NORMAL_CHAR", '/^(((?<![\\\])[^\\\])|([\\\].))*$/');
$strings = array_map("rtrim", file("test.txt"));
for ($i = 0, $x = count($strings); $i < $x; ++$i) {
echo (int)preg_match(REGEXP_NORMAL_CHAR, $strings[$i]) . " : " . $strings[$i] . PHP_EOL;
}
?>
s\" t\\ u\\\"\\\\\\ v\ w\\\\\ x\"\
1 : s\" 1 : t\\ 1 : u\\\"\\\\\\ 0 : v\ 0 : w\\\\\ 0 : x\"\
'#(\\\\|\\["\']|[^\\])*#'
<?php
header("Content-Type: text/plain; charset=UTF-8");
define("REGEXP_NORMAL_CHAR", '/^(((?<![\\\])[^\\\])|([\\\].))*$/');
$strings = array_map("rtrim", file("test.txt"));
for ($i = 0, $x = count($strings); $i < $x; ++$i) {
echo (int)preg_match(REGEXP_NORMAL_CHAR, $strings[$i]) . " : " . $strings[$i] . PHP_EOL;
}
?>
s\" t\\ u\\\"\\\\\\ v\ w\\\\\ x\"\
1 : s\" 1 : t\\ 1 : u\\\"\\\\\\ 0 : v\ 0 : w\\\\\ 0 : x\"\
/ ([\'"]) (?: (?<!\x5C) # treffe jedes Zeichen, dem kein Backslash vorausgeht [^\x5C] # und das kein Backslash ist | \x5C. # oder treffe die Zeichengruppe Backslash plus beliebiges Zeichen )*? \1 /sx
/ ([\'"]) (?: \x5C{2} # treffe zwei Backslashes | \x5C. # oder einen Backslash und ein beliebiges Zeichen | [^\x5C] # oder ein Zeichen, das kein Backslash ist )*? \1 /sx
/ ([\'"]) .*? # treffe beliebige Zeichen (?: $ # bis das Eingabeende erreicht ist (optional) | (?<!\x5C) # oder bis ein Anführungszeichen, dem eine gerade Anzahl (?:\x5C{2})* # Backslashes (egalisieren sich) vorausgeht, vor denen kein \1 # Backslash steht, erreicht wird ) /sx
3pm 6:27pm 22:31 2:05 2:05am
<time> ::= 3pm | 6:27pm | 22:31 | 2:05 | 2:05am
<time> ::= <withoutEnd> | <withEnd> <withoutEnd> ::= <hourA> | <hourA> ':' <minute> <hourA> ::= 0 | ... | 23 <minute> ::= 0 | ... | 59 <withEnd> ::= <hourB> <end> | <hourB> ':' <minute> <end> <hourB> ::= 1 | ... | 12 <end> ::= 'am' | 'pm'
Kommentar