简体   繁体   English

在Regex中使用Mysql中的Replace

[英]Using Replace in Mysql with Regex

I discovered a # of records in my table where a field seems to have carriage returns. 我在表中发现了一条记录,其中某个字段似乎有回车符。 I found them using: 我发现他们使用:

Select Field from Table WHERE Field REGEXP "\r\n"

I'd like to remove them but using regex in replace did not work: 我想删除它们,但在替换中使用正则表达式不起作用:

Update Table set Field=Replace(Field,REGEXP "\r\n",'') where Field REGEXP "\r\n"

As an aside I have found several fields that did NOT match the regex query but still show up in the memo field as broken e..g 顺便说一句,我发现几个与正则表达式查询不匹配的字段,但仍在备注字段中显示为损坏的例如

Queen

Anne

vs

Queen Ann

Is there any other Regex character I should be adding so I can search on any/all combinations and replace where I am not getting simply a space? 我是否应该添加其他正则表达式字符,以便我可以搜索任何/所有组合并替换不只是空格的位置?

You just want replace() : 您只想要replace()

Update Table
    set Field = Replace(Field, '\r\n', '')
    where Field REGEXP '\r\n';

MySQL should recognize '\\r' and '\\n' in any string (see here ). MySQL应该在任何字符串中识别'\\r''\\n' (请参阅此处 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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