webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
Namespaces | Functions
preg_helper.php File Reference

Namespaces

 preg_helper
 

Functions

 preg_merge ($glue, array $expressions, array $names=array())
 
 preg_strip ($expression)
 

Function Documentation

◆ preg_merge()

preg_merge (   $glue,
array  $expressions,
array  $names = array() 
)

Merges several regular expressions into one, using the indicated 'glue'.

This function takes care of individual modifiers so it's safe to use different modifiers on the individual expressions. The order of sub-matches is preserved as well. Numbered back-references are adapted to the new overall sub-match count. This means that it's safe to use numbered back-refences in the individual expressions! If $names is given, the individual expressions are captured in named sub-matches using the contents of that array as names. Matching pair-delimiters (e.g. "{…}") are currently not supported.

The function assumes that all regular expressions are well-formed. Behaviour is undefined if they aren't.

This function was created after a StackOverflow discussion. Much of it was written or thought of by “porneL” and “eyelidlessness”. Many thanks to both of them.

Parameters
string$glueA string to insert between the individual expressions. This should usually be either the empty string, indicating concatenation, or the pipe ("|"), indicating alternation. Notice that this string might have to be escaped since it is treated as a normal character in a regular expression (i.e. "/" will end the expression and result in an invalid output).
array$expressionsThe expressions to merge. The expressions may have arbitrary different delimiters and modifiers.
array$namesOptional. This is either an empty array or an array of strings of the same length as $expressions. In that case, the strings of this array are used to create named sub-matches for the expressions.
Returns
string An string representing a regular expression equivalent to the merged expressions. Returns FALSE if an error occurred.

◆ preg_strip()

preg_strip (   $expression)

Strips a regular expression string off its delimiters and modifiers. Additionally, normalizes the delimiters (i.e. reformats the pattern so that it could have used "/" as delimiter).

Parameters
string$expressionThe regular expression string to strip.
Returns
array An array whose first entry is the expression itself, the second an array of delimiters. If the argument is not a valid regular expression, returns FALSE.