pattern | - is a string that is a perl compatible regular expression as documented at: http://us.php.net/manual/en/ref.pcre.php This expression passed to this function should have delimiters and can contain the standard perl modifiers after the ending delimiter. | |
subject | -is the data to perform the match & capture on | |
group | - is the capture group that should be returned. This can be a numeric capture group or a named capture group. Numeric groups should be passed in as INT while named groups should be strings. |
- string that is the entire portion of subject which matches the pattern - if 0 is passed in as the group and pattern matches subject
- NULL - if pattern does not match the subject or group is not a valid capture group for the given pattern and subject.
Yields:
+----------------------------------------------------------+ | PREG_CAPTURE('/(.*?)(fox)/' , 'the quick brown fox' ,2 ) | +----------------------------------------------------------+ | fox | +----------------------------------------------------------+ *
SELECT PREG_CAPTURE('/(?:^|\s)(organic)(.*?[^\s]+)\s/i' ,products.title, 2 ) AS w FROM products HAVING w IS NOT NULL;
Yields: the word following organic in all of the product names
SELECT PREG_CAPTURE('/(?:^|\s)(organic)(?P<follow>.*?[^\s]+)\s/i' ,products.title, 'follow' ) AS w FROM products HAVING w IS NOT NULL;
Yields: the same as above but with using named capture group