正则(自编留平时自用)

来源:互联网 发布:举报网络诈骗投诉中心 编辑:程序博客网 时间:2024/05/13 18:46

在文档里查找一个最小(无嵌套)标签:  <([^<>]+)>[^<>]*<\/\1>


保留网页时:

(1)css

 查找css引用文本 :href="[^<>]*/([^/<>]*).css

替换里面的路径部分:href="新的路径/$1.css


同理:更改 js, 图片引用路径等


(2)js: 

引用:src="[^<>]*/([^/<>]*).js

替换:src="新的路径/$1.js


(3)图片: 

引用:

url\(("?)[^<>()]*/([^/<>()]*"?)\)

替换:url($1新的路径/$2)



日常:

(1)日期:^\d{4}-(1[012]|0?[1-9])-(0?[1-9]|[12]\d|3[01])$

          格式: 2015-09-02 或 2015-9-2  ,  月份<=12,日最大31


不解释,结合反向引用自己体会:

var englishPara=' ******if someone loves a flower, of which just one single blossom grows in all the millions and millions of stars, it is enough to make him happy just to look at the stars. he can say to himself, "somewhere, my flower is there…" but if the sheep eats the flower, in one moment all his stars will be darkened… and you think that is not important! ';
var ptn=/(\s*[^a-zA-Z\s]+\s*)([a-zA-Z])/g;
var res=englishPara.replace(ptn,function(m,n,o){return n+o.toUpperCase()});
   //首单词处理
   res=res.replace(/^([^a-zA-Z\s]*)([a-zA-Z])/,function(m,n,o){return n+o.toUpperCase()})


废弃css样式处理:

(border:1px[^;]*;)

/*$1*/


0 0
原创粉丝点击