Home >Database >Mysql Tutorial >Why Does MySQL Throw a \'Repetition-Operator Operand Invalid\' Regex Error, and How Can I Fix It?

Why Does MySQL Throw a \'Repetition-Operator Operand Invalid\' Regex Error, and How Can I Fix It?

Linda Hamilton
Linda HamiltonOriginal
2024-11-25 21:10:15537browse

Why Does MySQL Throw a

MySQL Regex Error: 'Repetition-Operator Operand Invalid'

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.


  1. >

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn