栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python的正则表达式re模块的常用方法

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python的正则表达式re模块的常用方法

1.re的简介
使用python的re模块,尽管不能满足所有复杂的匹配情况,但足够在绝大多数情况下能够有效地实现对复杂字符串的分析并提取出相关信息。python 会将正则表达式转化为字节码,利用 C 语言的匹配引擎进行深度优先的匹配。

复制代码 代码如下:
import re
print re.__doc__


可以查询re模块的功能信息,下面会结合几个例子说明。

2.re的正则表达式语法

正则表达式语法表如下:

语法 意义 说明
"." 任意字符
"^" 字符串开始 '^hello'匹配'helloworld'而不匹配'aaaahellobbb'
"$" 字符串结尾 与上同理
"*" 
0 个或多个字符(贪婪匹配)
<*>匹配chinaunix
"+"
1 个或多个字符(贪婪匹配)
与上同理
"?"
0 个或多个字符(贪婪匹配)
与上同理
*?,+?,??
以上三个取第一个匹配结果(非贪婪匹配) <*>匹配<BR></TD></TR> <TR> <TD>{m,n}<BR></TD> <TD>对于前一个字符重复m到n次,{m}亦可<BR></TD> <TD>a{6}匹配6个a、a{2,4}匹配2到4个a </TD></TR> <TR> <TD>{m,n}?<BR></TD> <TD>对于前一个字符重复m到n次,并取尽可能少<BR></TD> <TD>‘aaaaaa'中a{2,4}只会匹配2个 </TD></TR> <TR> <TD>"\"<BR></TD> <TD>特殊字符转义或者特殊序列 </TD> <TD><BR></TD></TR> <TR> <TD>[]<BR></TD> <TD>表示一个字符集 </TD> <TD>[0-9]、[a-z]、[A-Z]、[^0] </TD></TR> <TR> <TD>"|"<BR></TD> <TD>或 </TD> <TD>A|B,或运算 </TD></TR> <TR> <TD>(...)<BR></TD> <TD>匹配括号中任意表达式 </TD> <TD><BR></TD></TR> <TR> <TD>(?#...)<BR></TD> <TD>注释,可忽略 </TD> <TD><BR></TD></TR> <TR> <TD>(?=...)<BR></TD> <TD>Matches if ... matches next, but doesn't consume the string.<BR></TD> <TD>'(?=test)'  在hellotest中匹配hello </TD></TR> <TR> <TD>(?!...)<BR></TD> <TD>Matches if ... doesn't match next.<BR></TD> <TD>'(?!=test)'  若hello后面不为test,匹配hello<BR></TD></TR> <TR> <TD>(?<=...) <BR></TD> <TD>Matches if preceded by ... (must be fixed length).<BR></TD> <TD>'(?<=hello)test'  在hellotest中匹配test<BR></TD></TR> <TR> <TD>(?<!...)<BR></TD> <TD>Matches if not preceded by ... (must be fixed length).<BR></TD> <TD>'(?<!hello)test'  在hellotest中不匹配test<BR></TD></TR></TBODY></TABLE><BR>正则表达式特殊序列表如下: <br><br> <TABLE style="WIDTH: 60%" borderColor=#000000 cellSpacing=0 cellPadding=2 border=1> <TBODY> <TR> <TD>特殊序列符号<BR></TD> <TD>意义 </TD></TR> <TR> <TD>A<BR></TD> <TD>只在字符串开始进行匹配 </TD></TR> <TR> <TD>Z<BR></TD> <TD>只在字符串结尾进行匹配 </TD></TR> <TR> <TD>b<BR></TD> <TD>匹配位于开始或结尾的空字符串 </TD></TR> <TR> <TD>B<BR></TD> <TD>匹配不位于开始或结尾的空字符串 </TD></TR> <TR> <TD>d<BR></TD> <TD>相当于[0-9] </TD></TR> <TR> <TD>D<BR></TD> <TD>相当于[^0-9] </TD></TR> <TR> <TD>s<BR></TD> <TD>匹配任意空白字符:[tnrrv] </TD></TR> <TR> <TD>S<BR></TD> <TD>匹配任意非空白字符:[^tnrrv] </TD></TR> <TR> <TD>w<BR></TD> <TD>匹配任意数字和字母:[a-zA-Z0-9] </TD></TR> <TR> <TD>W<BR></TD> <TD>匹配任意非数字和字母:[^a-zA-Z0-9] </TD></TR></TBODY></TABLE><BR> <P><STRONG>3.re的主要功能函数</STRONG></P> <P>    常用的功能函数包括:compile、search、match、split、findall(finditer)、sub(subn)<BR>compile<BR>re.compile(pattern[, flags])<BR>作用:把正则表达式语法转化成正则表达式对象<BR>flags定义包括:<BR>re.I:忽略大小写<BR>re.L:表示特殊字符集 w, W, b, B, s, S 依赖于当前环境<BR>re.M:多行模式<BR>re.S:' . '并且包括换行符在内的任意字符(注意:' . '不包括换行符)<BR>re.U: 表示特殊字符集 w, W, b, B, d, D, s, S 依赖于 Unicode 字符属性数据库</P> <P>search<BR>re.search(pattern, string[, flags])<BR>search (string[, pos[, endpos]])<BR>作用:在字符串中查找匹配正则表达式模式的位置,返回 MatchObject 的实例,如果没有找到匹配的位置,则返回 None。</P> <P>match<BR>re.match(pattern, string[, flags])<BR>match(string[, pos[, endpos]])<BR>作用:match() 函数只在字符串的开始位置尝试匹配正则表达式,也就是只报告从位置 0 开始的匹配情况,而 search() 函数是扫描整个字符串来查找匹配。如果想要搜索整个字符串来寻找匹配,应当用 search()。</P> <P><STRONG>下面是几个例子:<BR></STRONG>例:最基本的用法,通过re.RegexObject对象调用</P> <P><U>复制代码</U> 代码如下:<BR>#!/usr/bin/env python<BR>import re<BR>r1 = re.compile(r'world')<BR>if r1.match('helloworld'):<BR>    print 'match succeeds'<BR>else:<BR>    print 'match fails'<BR>if r1.search('helloworld'):<BR>    print 'search succeeds'<BR>else:<BR>    print 'search fails' <BR></P> <P>说明一下:r是raw(原始)的意思。因为在表示字符串中有一些转义符,如表示回车'n'。如果要表示表需要写为'\'。但如果我就是需要表示一个''+'n',不用r方式要写为:'\n'。但使用r方式则为r'n'这样清晰多了。</P> <P>例:设置flag<BR><U>复制代码</U> 代码如下:<BR>#r2 = re.compile(r'n$', re.S)<BR>#r2 = re.compile('n$', re.S)<BR>r2 = re.compile('World$', re.I)<BR>if r2.search('helloworldn'):<BR>    print 'search succeeds'<BR>else:<BR>    print 'search fails' <BR><BR>例:直接调用<BR><U>复制代码</U> 代码如下:<BR>if re.search(r'abc','helloaaabcdworldn'):<BR>    print 'search succeeds'<BR>else:<BR>    print 'search fails' <BR></P> <P>split<BR>re.split(pattern, string[, maxsplit=0, flags=0])<BR>split(string[, maxsplit=0])<BR>作用:可以将字符串匹配正则表达式的部分割开并返回一个列表<BR>例:简单分析ip</P> <P><U>复制代码</U> 代码如下:<BR>#!/usr/bin/env python<BR>import re<BR>r1 = re.compile('W+')<BR>print r1.split('192.168.1.1')<BR>print re.split('(W+)', '192.168.1.1')<BR>print re.split('(W+)', '192.168.1.1', 1) <BR><BR>结果如下:<BR>['192', '168', '1', '1']<BR>['192', '.', '168', '.', '1', '.', '1']<BR>['192', '.', '168.1.1']</P> <P>findall<BR>re.findall(pattern, string[, flags])<BR>findall(string[, pos[, endpos]])<BR>作用:在字符串中找到正则表达式所匹配的所有子串,并组成一个列表返回<BR>例:查找[]包括的内容(贪婪和非贪婪查找)</P> <P><U>复制代码</U> 代码如下:<BR>#!/usr/bin/env python<BR>import re<BR>r1 = re.compile('([.*])')<BR>print re.findall(r1, "hello[hi]heldfsdsf[iwonder]lo")<BR>r1 = re.compile('([.*?])')<BR>print re.findall(r1, "hello[hi]heldfsdsf[iwonder]lo")<BR>print re.findall('[0-9]{2}',"fdskfj1323jfkdj")<BR>print re.findall('([0-9][a-z])',"fdskfj1323jfkdj")<BR>print re.findall('(?=www)',"afdsfwwwfkdjfsdfsdwww")<BR>print re.findall('(?<=www)',"afdsfwwwfkdjfsdfsdwww") <BR></P> <P>finditer<BR>re.finditer(pattern, string[, flags])<BR>finditer(string[, pos[, endpos]])<BR>说明:和 findall 类似,在字符串中找到正则表达式所匹配的所有子串,并组成一个迭代器返回。同样 RegexObject 有:</P> <P>sub<BR>re.sub(pattern, repl, string[, count, flags])<BR>sub(repl, string[, count=0])<BR>说明:在字符串 string 中找到匹配正则表达式 pattern 的所有子串,用另一个字符串 repl 进行替换。如果没有找到匹配 pattern 的串,则返回未被修改的 string。Repl 既可以是字符串也可以是一个函数。<BR>例:</P> <P><U>复制代码</U> 代码如下:<BR>#!/usr/bin/env python<BR>import re<BR>p = re.compile('(one|two|three)')<BR>print p.sub('num', 'one word two words three words apple', 2) <BR></P> <P>subn<BR>re.subn(pattern, repl, string[, count, flags])<BR>subn(repl, string[, count=0])</P> <P>说明:该函数的功能和 sub() 相同,但它还返回新的字符串以及替换的次数。同样 RegexObject 有:</P></div> </div> <div style="clear: both;"></div> <div class="author-info fl"> <div><span class="gray">转载请注明:</span>文章转载自 <a href="https://www.mshxw.com/" class="blue">www.mshxw.com</a></div> <div><span class="gray">本文地址:</span><a href="https://www.mshxw.com/it/36625.html" class="blue">https://www.mshxw.com/it/36625.html</a></div> </div> <div class="prev fl"> <p> <a style='text-align:left;' class='center-block text-center glyphicon glyphicon-collapse-down' href="https://www.mshxw.com/it/36620.html">上一篇 python dict remove数组删除(del,pop)</a> </p> <p> <a style='text-align:left;' class='center-block text-center glyphicon glyphicon-collapse-down' href="https://www.mshxw.com/it/36607.html">下一篇 python分割和拼接字符串</a> </p> </div> <div class="new_tag fl"> </div> </div> <div class="new_r fr" style="border-radius:10px;"> <div class="tui fl"> <h3>Python相关栏目本月热门文章</h3> <ul> <li><span>1</span><a href="https://www.mshxw.com/it/1041277.html" title="【Linux驱动开发】设备树详解(二)设备树语法详解">【Linux驱动开发】设备树详解(二)设备树语法详解</a></li> <li><span>2</span><a href="https://www.mshxw.com/it/1041273.html" title="别跟客户扯细节">别跟客户扯细节</a></li> <li><span>3</span><a href="https://www.mshxw.com/it/1041266.html" title="Springboot+RabbitMQ+ACK机制(生产方确认(全局、局部)、消费方确认)、知识盲区">Springboot+RabbitMQ+ACK机制(生产方确认(全局、局部)、消费方确认)、知识盲区</a></li> <li><span>4</span><a href="https://www.mshxw.com/it/1041261.html" title="【Java】对象处理流(ObjectOutputStream和ObjectInputStream)">【Java】对象处理流(ObjectOutputStream和ObjectInputStream)</a></li> <li><span>5</span><a href="https://www.mshxw.com/it/1041256.html" title="【分页】常见两种SpringBoot项目中分页技巧">【分页】常见两种SpringBoot项目中分页技巧</a></li> <li><span>6</span><a href="https://www.mshxw.com/it/1041299.html" title="一文带你搞懂OAuth2.0">一文带你搞懂OAuth2.0</a></li> <li><span>7</span><a href="https://www.mshxw.com/it/1041297.html" title="我要写整个中文互联网界最牛逼的JVM系列教程 | 「JVM与Java体系架构」章节:虚拟机与Java虚拟机介绍">我要写整个中文互联网界最牛逼的JVM系列教程 | 「JVM与Java体系架构」章节:虚拟机与Java虚拟机介绍</a></li> <li><span>8</span><a href="https://www.mshxw.com/it/1041296.html" title="【Spring Cloud】新闻头条微服务项目:FreeMarker模板引擎实现文章静态页面生成">【Spring Cloud】新闻头条微服务项目:FreeMarker模板引擎实现文章静态页面生成</a></li> <li><span>9</span><a href="https://www.mshxw.com/it/1041294.html" title="JavaSE - 封装、static成员和内部类">JavaSE - 封装、static成员和内部类</a></li> <li><span>10</span><a href="https://www.mshxw.com/it/1041291.html" title="树莓派mjpg-streamer实现监控及拍照功能调试">树莓派mjpg-streamer实现监控及拍照功能调试</a></li> <li><span>11</span><a href="https://www.mshxw.com/it/1041289.html" title="用c++写一个蓝屏代码">用c++写一个蓝屏代码</a></li> <li><span>12</span><a href="https://www.mshxw.com/it/1041285.html" title="从JDK8源码中看ArrayList和LinkedList的区别">从JDK8源码中看ArrayList和LinkedList的区别</a></li> <li><span>13</span><a href="https://www.mshxw.com/it/1041281.html" title="idea 1、报错java: 找不到符号 符号: 变量 log 2、转换成Maven项目">idea 1、报错java: 找不到符号 符号: 变量 log 2、转换成Maven项目</a></li> <li><span>14</span><a href="https://www.mshxw.com/it/1041282.html" title="在openwrt使用C语言增加ubus接口(包含C uci操作)">在openwrt使用C语言增加ubus接口(包含C uci操作)</a></li> <li><span>15</span><a href="https://www.mshxw.com/it/1041278.html" title="Spring 解决循环依赖">Spring 解决循环依赖</a></li> <li><span>16</span><a href="https://www.mshxw.com/it/1041275.html" title="SpringMVC——基于MVC架构的Spring框架">SpringMVC——基于MVC架构的Spring框架</a></li> <li><span>17</span><a href="https://www.mshxw.com/it/1041272.html" title="Andy‘s First Dictionary C++ STL set应用">Andy‘s First Dictionary C++ STL set应用</a></li> <li><span>18</span><a href="https://www.mshxw.com/it/1041271.html" title="动态内存管理">动态内存管理</a></li> <li><span>19</span><a href="https://www.mshxw.com/it/1041270.html" title="我的创作纪念日">我的创作纪念日</a></li> <li><span>20</span><a href="https://www.mshxw.com/it/1041269.html" title="Docker自定义镜像-Dockerfile">Docker自定义镜像-Dockerfile</a></li> </ul> </div> </div> </div> <!-- 公共尾部 --> <div class="link main"> <div class="link_tit"> <span class="on">热门相关搜索</span> </div> <div class="link_tab"> <div class="link_con"> <a href="http://www.mshxw.com/TAG_1/luyouqishezhi.html">路由器设置</a> <a href="http://www.mshxw.com/TAG_1/mutuopan.html">木托盘</a> <a href="http://www.mshxw.com/TAG_1/baotamianban.html">宝塔面板</a> <a href="http://www.mshxw.com/TAG_1/shaoerpython.html">儿童python教程</a> <a href="http://www.mshxw.com/TAG_1/xinqingdiluo.html">心情低落</a> <a href="http://www.mshxw.com/TAG_1/pengyouquan.html">朋友圈</a> <a href="http://www.mshxw.com/TAG_1/vim.html">vim</a> <a href="http://www.mshxw.com/TAG_1/shuangyiliuxueke.html">双一流学科</a> <a href="http://www.mshxw.com/TAG_1/zhuanshengben.html">专升本</a> <a href="http://www.mshxw.com/TAG_1/wodexuexiao.html">我的学校</a> <a href="http://www.mshxw.com/TAG_1/rijixuexiao.html">日记学校</a> <a href="http://www.mshxw.com/TAG_1/xidianpeixunxuexiao.html">西点培训学校</a> <a href="http://www.mshxw.com/TAG_1/qixiuxuexiao.html">汽修学校</a> <a href="http://www.mshxw.com/TAG_1/qingshu.html">情书</a> <a href="http://www.mshxw.com/TAG_1/huazhuangxuexiao.html">化妆学校</a> <a href="http://www.mshxw.com/TAG_1/tagouwuxiao.html">塔沟武校</a> <a href="http://www.mshxw.com/TAG_1/yixingmuban.html">异形模板</a> <a href="http://www.mshxw.com/TAG_1/xinandaxuepaiming.html">西南大学排名</a> <a href="http://www.mshxw.com/TAG_1/zuijingpirenshengduanju.html">最精辟人生短句</a> <a href="http://www.mshxw.com/TAG_1/6bujiaonizhuihuibeipian.html">6步教你追回被骗的钱</a> <a href="http://www.mshxw.com/TAG_1/nanchangdaxue985.html">南昌大学排名</a> <a href="http://www.mshxw.com/TAG_1/qingchaoshierdi.html">清朝十二帝</a> <a href="http://www.mshxw.com/TAG_1/beijingyinshuaxueyuanpaiming.html">北京印刷学院排名</a> <a href="http://www.mshxw.com/TAG_1/beifanggongyedaxuepaiming.html">北方工业大学排名</a> <a href="http://www.mshxw.com/TAG_1/beijinghangkonghangtiandaxuepaiming.html">北京航空航天大学排名</a> <a href="http://www.mshxw.com/TAG_1/shoudoujingjimaoyidaxuepaiming.html">首都经济贸易大学排名</a> <a href="http://www.mshxw.com/TAG_1/zhongguochuanmeidaxuepaiming.html">中国传媒大学排名</a> <a href="http://www.mshxw.com/TAG_1/shoudoushifandaxuepaiming.html">首都师范大学排名</a> <a href="http://www.mshxw.com/TAG_1/zhongguodezhidaxue(beijing)paiming.html">中国地质大学(北京)排名</a> <a href="http://www.mshxw.com/TAG_1/beijingxinxikejidaxuepaiming.html">北京信息科技大学排名</a> <a href="http://www.mshxw.com/TAG_1/zhongyangminzudaxuepaiming.html">中央民族大学排名</a> <a href="http://www.mshxw.com/TAG_1/beijingwudaoxueyuanpaiming.html">北京舞蹈学院排名</a> <a href="http://www.mshxw.com/TAG_1/beijingdianyingxueyuanpaiming.html">北京电影学院排名</a> <a href="http://www.mshxw.com/TAG_1/zhongguohuquxueyuanpaiming.html">中国戏曲学院排名</a> <a href="http://www.mshxw.com/TAG_1/hebeizhengfazhiyexueyuanpaiming.html">河北政法职业学院排名</a> <a href="http://www.mshxw.com/TAG_1/hebeijingmaodaxuepaiming.html">河北经贸大学排名</a> <a href="http://www.mshxw.com/TAG_1/tianjinzhongdeyingyongjishudaxuepaiming.html">天津中德应用技术大学排名</a> <a href="http://www.mshxw.com/TAG_1/tianjinyixuegaodengzhuankexuejiaopaiming.html">天津医学高等专科学校排名</a> <a href="http://www.mshxw.com/TAG_1/tianjinmeishuxueyuanpaiming.html">天津美术学院排名</a> <a href="http://www.mshxw.com/TAG_1/tianjinyinlexueyuanpaiming.html">天津音乐学院排名</a> <a href="http://www.mshxw.com/TAG_1/tianjingongyedaxuepaiming.html">天津工业大学排名</a> <a href="http://www.mshxw.com/TAG_1/beijinggongyedaxuegengdanxueyuanpaiming.html">北京工业大学耿丹学院排名</a> <a href="http://www.mshxw.com/TAG_1/beijingjingchaxueyuanpaiming.html">北京警察学院排名</a> <a href="http://www.mshxw.com/TAG_1/tianjinkejidaxuepaiming.html">天津科技大学排名</a> <a href="http://www.mshxw.com/TAG_1/beijingyoudiandaxue(hongfujiaoou)paiming.html">北京邮电大学(宏福校区)排名</a> <a href="http://www.mshxw.com/TAG_1/beijingwanglaozhiyexueyuanpaiming.html">北京网络职业学院排名</a> <a href="http://www.mshxw.com/TAG_1/beijingdaxueyixuebupaiming.html">北京大学医学部排名</a> <a href="http://www.mshxw.com/TAG_1/hebeikejidaxuepaiming.html">河北科技大学排名</a> <a href="http://www.mshxw.com/TAG_1/hebeidezhidaxuepaiming.html">河北地质大学排名</a> <a href="http://www.mshxw.com/TAG_1/hebeitiyoxueyuanpaiming.html">河北体育学院排名</a> </div> </div> </div> <div class="footer"> <div class="dl_con"> <div class="width1200"> <dl> <dt>学习工具</dt> <dd><a href="https://www.mshxw.com/tools/algebra/" title="代数计算器">代数计算器</a></dd> <dd><a href="https://www.mshxw.com/tools/trigonometry/" title="三角函数计算器">三角函数</a></dd> <dd><a href="https://www.mshxw.com/tools/analytical/" title="解析几何">解析几何</a></dd> <dd><a href="https://www.mshxw.com/tools/solidgeometry/" title="立体几何">立体几何</a></dd> </dl> <dl> <dt>知识解答</dt> <dd><a href="https://www.mshxw.com/ask/1033/" title="教育知识">教育知识</a></dd> <dd><a href="https://www.mshxw.com/ask/1180/" title="百科知识">百科知识</a></dd> <dd><a href="https://www.mshxw.com/ask/1155/" title="生活知识">生活知识</a></dd> <dd><a class="https://www.mshxw.com/ask/1199/" title="常识知识">常识知识</a></dd> </dl> <dl> <dt>写作必备</dt> <dd><a href="https://www.mshxw.com/zuowen/1128/" title="作文大全">作文大全</a></dd> <dd><a href="https://www.mshxw.com/zuowen/1130/" title="作文素材">作文素材</a></dd> <dd><a href="https://www.mshxw.com/zuowen/1132/" title="句子大全">句子大全</a></dd> <dd><a href="https://www.mshxw.com/zuowen/1154/" title="实用范文">实用范文</a></dd> </dl> <dl class="mr0"> <dt>关于我们</dt> <dd><a href="https://www.mshxw.com/about/index.html" title="关于我们" rel="nofollow">关于我们</a></dd> <dd><a href="https://www.mshxw.com/about/contact.html" title="联系我们" rel="nofollow">联系我们</a></dd> <dd><a href="https://www.mshxw.com/sitemap/" title="网站地图">网站地图</a></dd> </dl> <div class="dl_ewm"> <div class="wx"> <img src="https://www.mshxw.com/skin/sinaskin//kaotop/picture/gzh.jpg" alt="交流群"> <p>名师互学网交流群</p> </div> <div class="wx"><img src="https://www.mshxw.com/skin/sinaskin//kaotop/picture/weixin.jpg" alt="名师互学网客服"> <p>名师互学网客服</p> </div> </div> </div> </div> <div class="copyright"> <p>名师互学网 版权所有 (c)2021-2022 ICP备案号:<a href="https://beian.miit.gov.cn" rel="nofollow">晋ICP备2021003244-6号</a> </p> </div> </div> <!-- 手机端 --> <div class="m_foot_top"> <img src="https://www.mshxw.com/foot.gif" width="192" height="27" alt="我们一直用心在做"><br/> <a href="https://www.mshxw.com/about/index.html">关于我们</a> <a href="https://www.mshxw.com/archiver/">文章归档</a> <a href="https://www.mshxw.com/sitemap">网站地图</a> <a href="https://www.mshxw.com/about/contact.html">联系我们</a> <p>版权所有 (c)2021-2022 MSHXW.COM</p> <p>ICP备案号:<a href="https://beian.miit.gov.cn/" rel="nofollow">晋ICP备2021003244-6号</a></p> </div> <div class="to_top" style="display:none;"><img src="https://www.mshxw.com/skin/sinaskin//kaotop/picture/to_top.png"></div> <!--广告!--> <script type="text/javascript" src="https://www.mshxw.com/skin/sinaskin//kaotop/js/top.js"></script> <script src="https://www.mshxw.com/skin/sinaskin//kaotop/js/fixed.js" type="text/javascript"></script> <!--头条搜索!--> <script> (function(){ var el = document.createElement("script"); el.src = "https://lf1-cdn-tos.bytegoofy.com/goofy/ttzz/push.js?018f42187355ee18d1bfcee0487fc91a76ac6319beb05b7dc943033ed22c446d3d72cd14f8a76432df3935ab77ec54f830517b3cb210f7fd334f50ccb772134a"; el.id = "ttzz"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(el, s); })(window) </script> <!--头条搜索结束!--> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?e05fec1c87ee5ca07f1ce57d093866c4"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </div> </div> <script type="text/javascript"> $(".alert_kf").click(function() { mantis.requestChat(); }); </script> <script type="text/javascript"> var mySwiper_weixin = new Swiper('.pc_swiper_weixin', { autoplay: 3000, //可选选项,自动滑动 loop: true, speed: 1000, pagination: '.swiper-pagination', paginationClickable: true, }) </script> <script type="text/javascript"> $(function() { $(window).scroll(function() { if ($(window).scrollTop() > 100) { $(".to_top").fadeIn(1000); } else { $(".to_top").fadeOut(1000); } }); $(".to_top").click(function() { if ($('html').scrollTop()) { $('html').animate({ scrollTop: 0 }, 300); return false; } $('body').animate({ scrollTop: 0 }, 300); return false; }); }); </script> </body> </html>