简体   繁体   中英

How do I search and replace using regex in MySQL?

I'm trying to update a field which contains HTML and I want to find all the rows that have forms in them and remove the form tags and anything in between them, however I'm running into problems with my select and the regex.

SELECT * FROM db.table WHERE body REGEXP "<form[^>].+?>.+?</form>";

and the error I get says: 'repetition-operator operand invalid' from regexp.

I was hoping to make that SELECT into a subselect for an update query but I'm stuck at this point.

I think your problem is in your form expression. Try the following:

"<form[^>]*>.+?</form>"

Remember that MySQL supports a limited set of regular expression matching and testing.

See this document .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM