When attempting to use a regular expression to select results from a MySQL table, you might encounter an error stating "#1139 - Got error 'repetition-operator operand invalid' from regexp." This error arises from the use of the '?' quantifier in a MySQL regular expression.
MySQL's regular expression implementation follows the POSIX 1003.2 standard, which doesn't support the '?' quantifier as a lazy (non-greedy) modifier for star and plus quantifiers (e.g., ? and *?).
To resolve this error, replace the '?' quantifier with its greedy counterpart. For instance, instead of using '?src="http://www', use 'src="http://www' to match any number of characters before "src="http://www".
Additionally, to avoid matching unwanted patterns (e.g., some style/" src="a.png">), you can use a negated character class like '1*src="http://www''. This matches occurrences of ') before the 'src="http://www' expression.
Remember, the double quotes ('") don't need to be escaped, and the .* quantifier is implied at the beginning of the regular expression.
The above is the detailed content of Why Does MySQL Throw a \'Repetition-Operator Operand Invalid\' Regex Error, and How Can I Fix It?. For more information, please follow other related articles on the PHP Chinese website!