regex - MySQL find and replace XXX if it's between YYY and ZZZ -
i'm working on wordpress-based project , need batch edit posts database.
at moment have cells, content text <pre> text\r\ntext\r\ntext </pre>
what need find \r\n strings , replace them \r\n\r\n. far have this:
update `table_name` set `field_name` = replace(field_name, '\r\n', '\r\n\r\n\') the issue is, there \r\n\ text outside <pre> tags, don't want affect. that's why need find (start: '<pre>' end: '</pre>') before calling replace. have no idea how in mysql.
when web searching, found stuff regex have no idea how works.
mysql doesn't have regexp replace functionality. i'd have 2 options - either create user defined function kind of replacement, or, if can't / don't know how to, have use script/program written in different language. may e.g. php script connect db , desired replacement. way dump table containing posts file, use sed or similar , import data once again.
using sed take less time php , syntax easy learn.
whatever choose remember it's idea make backup before.
Comments
Post a Comment