#1139 – Got error ‘repetition-operator operand invalid’ from regexp

According to the MySQL manual

MySQL uses Henry Spencer’s implementation of regular expressions, which is aimed at conformance with POSIX 1003.2

POSIX regexes don’t support using the question mark ? as a non-greedy (lazy) modifier to the star and plus quantifiers like PCRE (Perl Compatible Regular Expressions). This means you can’t use +? and *?

It looks like you’ll just have to use the greedy version, which should still work. To avoid the matching of things like <img style="/*some style*/" src="https://stackoverflow.com/questions/18317183/a.png"> <script src="www.example.com/js/abc.js">, you can use a negated character class:

'<img[^>]*src="http://www'

Note: The " doesn’t have to escaped and the .* at the beginning is implied.

Leave a Comment