XML technologies / Regular expressions / PHP / “Missing” preg functions / Checking a regex for correct syntax

(Excerpt from "Regular expressions" by Jeffrey E. F. Friedl)

Here is another function that checks the syntax of a bare regex, without delimiters or modifiers. It uses the two functions introduced earlier and returns an error message for invalid syntax, or the Boolean value ‘false’ otherwise.

/*
 * Gibt bei einem Regex-Syntaxfehler eine Fehlermeldung zurück,
 * bei einer gültigen Regex den Wert false.
 */
function preg_regex_error($regex)
{
    return preg_pattern_error(preg_regex_to_pattern($regex));
}

  

 

 

 

German edition copyright © 2008 by O’Reilly Verlag GmbH & Co. KG
You may print the online version for private use.
Otherwise, this chapter from "Reguläre Ausdrücke" is subject to the same terms as the bound edition: the work and all its parts are protected by copyright. All rights reserved, including reproduction, translation, microfilming, storage and processing in electronic systems.

O’Reilly Verlag GmbH & Co. KG, Balthasarstr. 81, 50670 Köln

back to top