Home > CMS Tutorial > DEDECMS > body text

How does Dreamweaver CMS search and replace the custom content of the database in batches through regular expressions?

藏色散人
Release: 2019-12-18 09:26:22
Original
2436 people have browsed it

How does Dreamweaver CMS search and replace the custom content of the database in batches through regular expressions?

织梦cms如何通过正则批量查找替换数据库的自定义内容?

正则的表达式在MY SQL中也有应用,但是在具体将查找的东西直接进行Replace的时候目前还不能解决,幸好后台中有个dede利用正则,利用dede正则批量替换数据库中内容,这样我们完全减小了自己的工作量了

推荐学习:织梦cms

  

例如网站的一个例子

是替换一个div中的内容,摘抄实践下,关键还是自己去体会,多用下正则,还是不错的、正则相关的文章我在我的博客中也多次提到了他的多种运用途径。如果你都掌握好它的话,你的工作效率就会成倍的提高了。

下面这个正则的用途是查找数据库的中自定义的DIV层中运用,一般这种用法你在采集,或者,用word直接添加内容后会用到。

看看这个是如何去除的。

例子一,去除简单自定义内容内容

选择数据表与字段:dede_addonarticle

替换方式:选择正则表达式

主键字段:aid

被替换内容:MM[\d]*GG

选择字段:body(这表是存储文章内容的),选择单选框:正则表达式,主键字段填写"aid",被替换内容为上面的正则:

例:MM[\d]*GG

替换为:可为空,也可填写你想置换为的内容。

替换条件:如果是全部,就不填写。开始测试时,先备份了数据库,然后仅替换一篇文章,条件中填写:aid=888,如果是分类,就填写:typeid=18,这样缩小替换范围,避免出错。

填写安全确认码,替换就ok了,

例子二,去除

*
内容

<div style="background-color: #fff9ee; text-align: center"><font style="font-weight: bold;">文章地址址:<br 
/>//www.jb51.net/<br /></font> </div>
Copy after login

上述代码,是一个不错的style,大家可以显示下,调试效果不错。

可以利用以下正则来替换:

]*\">(.*)

在dede后台,选择:核心–数据库内容替换–选择表: 

选择数据表与字段:dede_addonarticle

替换方式:选择正则表达式

主键字段:aid

被替换内容:

]*\">(.*)

选择字段:body(这表是存储文章内容的),选择单选框:正则表达式,主键字段填写"aid",被替换内容为上面的正则:

例:

]*\">(.*)

替换为:可为空,也可填写你想置换为的内容。

替换条件:如果是全部,就不填写。 

注意:开始测试时,先备份了数据库,然后仅替换一篇文章,条件中填写:aid=8880,如果是分类,就填写:typeid=18,这样缩

小替换范围,避免出错。

填写安全确认码,替换就ok了,注意这个安全确认码会有失效周期,但它自己不提示,也有这个可能,会选择替换无反应,遇见

这情况,只有刷新当前页面了。

很完整了吧!其它正则参考:http://bbs.dedecms.com/214856.html,这个当中的也不完整,也不太正确,需要对比来修改调试

,很费时间。 

正则是个好技术,有着很强大的应用,花了点时间看,你的工作效果会大陪的提高!

这是我在处理文章时用到一些正则表达式,里面有你要的。在Editplus中使用。

在表:dede_addonarticle中,body字段即是文章内容。

过滤Table相关的:

]*)>||||||| 

正则: width=\"[0-9][0-9][0-9]\"| width=[0-9][0-9][0-9]| height=\"[0-9][0-9][0-9]\"| height=[0-9][0-9][0-9],

说明:过虑height、Width。 

正则:

]*\">|
]*>|
|
, note: matches
or
.

Regular: style=\"[^"]*\"| style=[^"]*, note: Match Style="border:"

Regular: ]*)>(.*), note: matching

regular: ]*>|||]*>|| , note: matches and

Regular: border="[0-9]"| border=[0-9], note: matching border=""

Regular: ]*>|| , note: matching

regular: id=[^ ]*| id=\"[^ ]*\" , note: matching id=""

regular: title=[0-9][^ ]*| title=\"[0-9][^ ]*\"| alt=[0-9 ][^ ]*| alt=\"[0-9][^ ]*\"| alt=[a-z][^ ]*| alt=\"[a

-z][^ ]* \", Note: Match Title or alt

Regular: ]*–>, Description: Match HTML comment

Regular: ]*)>(.*), Description: Match all content between <script></script>

Regular: class=[a-z][^ | ^>]*| class=\"[a-z][^ |^>]*\", description: Clean up class="", fully tested

Regular:|||||||

Regular:

]*>|

|

| align=left|||
|]*)>|

Regular expression is a universal standard, and most computer languages ​​support regular expressions, including as3, Here are some commonly used regular expression statements, so you don’t have to write them yourself when you use them

^[0-9]*[1-9][0-9]*$ //Matching Positive integer

^-[0-9]*[1-9][0-9]*$ //Match negative integer

^-?\d $ //Match integer

^\d (\.\d )?$  //Match non-negative floating point numbers (positive floating point numbers 0)

^(([0-9] \.[0-9] *[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9] )|([0-9]*[1 -9][0-9]*))$ //Match positive floating point numbers

^((-\d (\.\d )?)|(0 (\.0 )?))$ //Match non-positive floating point numbers (negative floating point number 0)

^(-(([0-9] \.[0-9]*[1-9][0-9]*)| ([0-9]*[1-9][0-9]*\.[0-9] )|([0-9]*[1-9][0-9]*)))$ / /Match negative floating point numbers

^(-?\d )(\.\d )?$ //Match floating point numbers

^[A-Za-z] $ //Match by A string of 26 English letters

^[A-Z] $ // Matches a string of 26 uppercase letters

^[a-z] $ // Matches a string of 26 uppercase letters A string consisting of lowercase English letters

^[A-Za-z0-9] $ //Match a string consisting of numbers and 26 English letters

^\w $ / / Matches a string consisting of numbers, 26 English letters or underscores

^[\w-] (\.[\w-] )*@[\w-] (\.[\w- ] ) $ //Match email address

^[a-zA-z] ://Match (\w (-\w )*)(\.(\w (-\w )*)) *(\?\S*)?$ //Match url

Regular expression matching Chinese characters: [\u4e00-\u9fa5]

Match double-byte characters (including Chinese characters in (within): [^\x00-\xff]

Regular expression matching blank lines:\n[\s| ]*\r

Regular expression matching HTML tags:/ <(.*)>.*<\/>|<(.*) \/>/

Regular expression matching leading and trailing spaces: (^\s*)|( \s*$)

Regular expression matching email addresses: \w ([- .]\w )*@\w ([-.]\w )*\.\w ([-. ]\w )*

Regular expression matching URL: ^[a-zA-z] ://(\w (-\w )*)(\.(\w (-\w) )*))*(\?\S*)?$

Is the matching account legal (starting with a letter, 5-16 bytes allowed, alphanumeric underscores allowed): ^[a-zA-Z][ a-zA-Z0-9_]{4,15}$

Matches domestic phone numbers: (\d{3}-|\d{4}-)?(\d{8}|\d {7})?

Matches Tencent QQ number: ^[1-9]*[1-9][0-9]*$

The following table shows the metacharacters and their regular expressions A complete list of behaviors in the context of an expression:

\ Marks the next character as a special character, or a literal character, or a backreference, or an octal escape character.

^ Matches the beginning of the input string. If the RegExp object's Multiline property is set, ^ also matches the position after '\n' or '\r'.

$ Matches the end position of the input string. If the Multiline property of the RegExp object is set, $ also matches the position before '\n' or '\r'.

* Matches the preceding subexpression zero or more times.

Matches the previous subexpression one or more times. Equivalent to {1,}.

? Matches the preceding subexpression zero or one time. ? Equivalent to {0,1}.

{n} n 是一个非负整数,匹配确定的n 次。 

{n,} n 是一个非负整数,至少匹配n 次。 

{n,m} m 和 n 均为非负整数,其中n <= m。最少匹配 n 次且最多匹配 m 次。在逗号和两个数之间不能有空格。 

? 当该字符紧跟在任何一个其他限制符 (*, +, ?, {n}, {n,}, {n,m}) 后面时,匹配模式是非贪婪的。非贪婪模式尽可能少的匹

配所搜索的字符串,而默认的贪婪模式则尽可能多的匹配所搜索的字符串。 

. 匹配除 "\n" 之外的任何单个字符。要匹配包括 '\n' 在内的任何字符,请使用象 '[.\n]' 的模式。 

(pattern) 匹配pattern 并获取这一匹配。 

(?:pattern) 匹配pattern 但不获取匹配结果,也就是说这是一个非获取匹配,不进行存储供以后使用。

(?=pattern) 正向预查,在任何匹配 pattern 的字符串开始处匹配查找字符串。这是一个非获取匹配,也就是说,该匹配不需要

获取供以后使用。 

(?!pattern) 负向预查,与(?=pattern)作用相反 

x|y 匹配 x 或 y。 

[xyz] 字符集合。 

[^xyz] 负值字符集合。 

[a-z] 字符范围,匹配指定范围内的任意字符。 

[^a-z] 负值字符范围,匹配任何不在指定范围内的任意字符。 

\b 匹配一个单词边界,也就是指单词和空格间的位置。 

\B 匹配非单词边界。 

\cx 匹配由x指明的控制字符。 

\d 匹配一个数字字符。等价于 [0-9]。 

\D 匹配一个非数字字符。等价于 [^0-9]。 

\f 匹配一个换页符。等价于 \x0c 和 \cL。 

\n 匹配一个换行符。等价于 \x0a 和 \cJ。 

\r 匹配一个回车符。等价于 \x0d 和 \cM。 

\s 匹配任何空白字符,包括空格、制表符、换页符等等。等价于[ \f\n\r\t\v]。 

\S 匹配任何非空白字符。等价于 [^ \f\n\r\t\v]。 

\t 匹配一个制表符。等价于 \x09 和 \cI。 

\v 匹配一个垂直制表符。等价于 \x0b 和 \cK。 

\w 匹配包括下划线的任何单词字符。等价于'[A-Za-z0-9_]'。 

\W 匹配任何非单词字符。等价于 '[^A-Za-z0-9_]'。 

\xn 匹配 n,其中 n 为十六进制转义值。十六进制转义值必须为确定的两个数字长。 

\num 匹配 num,其中num是一个正整数。对所获取的匹配的引用。 

\n 标识一个八进制转义值或一个后向引用。如果 \n 之前至少 n 个获取的子表达式,则 n 为后向引用。否则,如果 n 为八进

制数字 (0-7),则 n 为一个八进制转义值。 

\nm 标识一个八进制转义值或一个后向引用。如果 \nm 之前至少有is preceded by at least nm 个获取得子表达式,则 nm 为

后向引用。如果 \nm 之前至少有 n 个获取,则 n 为一个后跟文字 m 的后向引用。如果前面的条件都不满足,若 n 和 m 均为

八进制数字 (0-7),则 \nm 将匹配八进制转义值 nm。 

\nml 如果 n 为八进制数字 (0-3),且 m 和 l 均为八进制数字 (0-7),则匹配八

关于批量替换 正则表达式

这是我在处理文章时用到一些正则表达式,里面有你要的。在Editplus中使用。

在表:dede_addonarticle中,body字段即是文章内容。

过滤Table相关的:

]*)>|||||||

还有一些,可供你参考,我加了一些注释,发个贴太累了,哎~~~自己摸索吧:

正则: width=\"[0-9][0-9][0-9]\"| width=[0-9][0-9][0-9]| height=\"[0-9][0-9][0-9]\"| height=[0-9][0-9][0-9],说明:过虑height、Width。

------------------------------------------------------

正则:

]*\">|
]*>|
|
, note: matches
or
.

-------------------------------------------------- ----------

Regular: style=\"[^"]*\"| style=[^"]*, note: Match Style="border:"

-------------------------------------------------- -------

Regular: ]*)>(.*), note: matches

------------------------------------ ------------------

Regular: ]*>|||< ;strong [^>]*>|| , note: matches and

--------- --------------------------------------------------

Regular: border="[0-9]"| border=[0-9], note: match border=""

----------------- -------------------------------------

Regular: ]*>|| , note: matches

------------------- ----------------------------------

Regular: id=[^ ]*| id=\"[^ ]*\", note: match id=""

-------------------------- ----------------------------

Regular: title=[0-9][^ ]*| title= \"[0-9][^ ]*\"| alt=[0-9][^ ]*| alt=\"[0-9][^ ]*\"| alt=[a-z][^ ] *| alt=\"[a-z][^ ]*\", note: match Title or alt

--------------------- --------------------------------

Regular: , Description: Match HTML comments

--------------------------------- ---------------------

Regular: ]*)>(.*)

------------------------ -----------------------------

Regular: class=[a-z][^ |^>]* | class=\"[a-z][^ |^>]*\", description: Clean up class="", fully tested

-------------- ----------------------------------------

Regular: < table([^>]*)>|||||||

-------------------------------------------------- ----------

Regular:

]*>|

|

| align=left|| |
|
|]*)>|

The above is the detailed content of How does Dreamweaver CMS search and replace the custom content of the database in batches through regular expressions?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!