admin 管理员组文章数量: 1184232
常年玩电脑的,总会多多少少碰到在一个地方复制了字符串后,需要删删减减,
而且是有规律的。
比如,百度网盘分享的结果,他不是单一网址,是一段字符串。
当你有一堆这样的分享链接的时候,但只想要纯链接,这时候怎么办。
我以前都是用notepad++去正则替换。。每次都要替换,虽然不是太麻烦,但是也很恶心。
Notepad++在这里:
可以看的到吧,普通字符串替换很多,还有正则替换。如果你的工作中经常有这样的替换,
看看下面这个小巧却很实用的软件吧。博主自己写的,实在是受不了替换的苦了。
这个是举例噢。可以自己生成单独的方案,下次一选就直接可以替换。
上图的作用,就是用在淘宝闲鱼一些平台,像自动发货通用发货的话,需要一个商品码,我这个是为了统一所有商品的商品码,就是整个标题的前15个正常字符,去掉特殊符号后的结果。要不然每次还得backspace一个一个删。
再看第二个图,也都是我自己应用的场景。
用于网盘链接转换,第一种就直接发布在外面,第二种就是带tab符的,直接粘在excel里就可以了。
哪怕再复杂的替换操作,大不了用正则就好了。
看的懂的就拿走用吧。看不懂的估计也就看不懂了。
带走地址:
顺便附上mainform的源码。
import win.ui;
import console;
import preg;
import fsys;
/*DSG{{*/
mainForm = win.form(cls="EMAO_FORM";text="文本格式替换小助手 - wangpanmao.com";right=847;bottom=650;border="thin")
mainForm.add(
Btn_Money={cls="plus";text="打赏鼓励(&C)";left=680;top=437;right=832;bottom=488;dr=1;dt=1;font=LOGFONT(h=-16;name='微软雅黑';weight=700);notify=1;z=11};
Btn_SaveProject={cls="button";text="保存方案(&S)";left=720;top=387;right=832;bottom=419;dr=1;dt=1;font=LOGFONT(h=-14;name='微软雅黑');z=7};
Btn_Start={cls="plus";text="开始替换(&R)";left=488;top=437;right=664;bottom=488;dr=1;dt=1;font=LOGFONT(h=-16;name='微软雅黑';weight=700);iconStyle={align="left";font=LOGFONT(h=-19;name='iconfont');padding={left=30}};notify=1;z=14};
CB_ProjectName={cls="combobox";left=576;top=392;right=712;bottom=416;dr=1;dt=1;edge=1;font=LOGFONT(name='微软雅黑');items={};mode="dropdown";z=9};
P1={cls="edit";left=488;top=240;right=656;bottom=376;dr=1;dt=1;edge=1;font=LOGFONT(name='微软雅黑');multiline=1;vscroll=1;z=12};
P2={cls="edit";left=664;top=240;right=832;bottom=376;dr=1;dt=1;edge=1;font=LOGFONT(name='微软雅黑');multiline=1;vscroll=1;z=13};
T1={cls="edit";left=488;top=56;right=656;bottom=208;dr=1;dt=1;edge=1;font=LOGFONT(name='微软雅黑');multiline=1;vscroll=1;z=2};
T2={cls="edit";left=664;top=56;right=832;bottom=208;dr=1;dt=1;edge=1;font=LOGFONT(name='微软雅黑');multiline=1;vscroll=1;z=3};
TB_result={cls="edit";left=8;top=288;right=472;bottom=488;db=1;dl=1;dr=1;dt=1;edge=1;font=LOGFONT(name='微软雅黑');multiline=1;vscroll=1;z=17};
custom={cls="custom";text="自定义控件";left=8;top=496;right=840;bottom=642;bgcolor=12639424;db=1;dl=1;dr=1;z=10};
groupbox={cls="groupbox";text="【替换方案】";left=480;top=8;right=840;bottom=427;dr=1;dt=1;edge=1;font=LOGFONT(name='微软雅黑');z=1};
source={cls="edit";left=8;top=40;right=472;bottom=248;dl=1;dr=1;dt=1;edge=1;font=LOGFONT(name='微软雅黑');multiline=1;vscroll=1;z=6};
static={cls="static";text="要查找的字符串";left=488;top=32;right=656;bottom=56;dr=1;dt=1;font=LOGFONT(name='微软雅黑');transparent=1;z=4};
static2={cls="static";text="替换后的字符串";left=664;top=32;right=832;bottom=56;dr=1;dt=1;font=LOGFONT(name='微软雅黑');transparent=1;z=5};
static3={cls="static";text="方案列表:";left=488;top=392;right=583;bottom=416;dr=1;dt=1;font=LOGFONT(h=-16;name='微软雅黑');transparent=1;z=8};
static4={cls="static";text="要查找的正则字符串";left=488;top=216;right=656;bottom=240;dr=1;dt=1;font=LOGFONT(name='微软雅黑');transparent=1;z=15};
static5={cls="static";text="替换后的正则字符串";left=664;top=216;right=832;bottom=240;dr=1;dt=1;font=LOGFONT(name='微软雅黑');transparent=1;z=16};
static6={cls="static";text="源字符串";left=8;top=8;right=176;bottom=32;dl=1;dt=1;font=LOGFONT(h=-16;name='微软雅黑');transparent=1;z=18};
static7={cls="static";text="替换结果";left=8;top=256;right=176;bottom=280;dl=1;dt=1;font=LOGFONT(h=-16;name='微软雅黑');transparent=1;z=19}
)
/*}}*/
/*myUI*/ mainForm.loadForm("/dlg/UI.aardio")
mainForm.Btn_SaveProject.oncommand = function(id,event){
pName = string.trim( mainForm.CB_ProjectName.text );
if( pName == "" ){
return mainForm.msgboxErr("方案名称为空!");
}
pm = string.matches( pName, "[:\w]" );
if( #pm != string.len(pName) ){
return mainForm.msgboxErr("方案名称只能用汉字,数字以及英文字母!");
}
//建文件夹
if( !io.exist("strRep_cache") ) {
io.createDir("strRep_cache");
}
if( !io.exist("strRep_cache/"++pName) ) {
io.createDir("strRep_cache/"++pName);
}
string.save("strRep_cache/" ++ pName ++ "/1.txt", mainForm.T1.text );
string.save("strRep_cache/" ++ pName ++ "/2.txt", mainForm.T2.text );
string.save("strRep_cache/" ++ pName ++ "/3.txt", mainForm.P1.text );
string.save("strRep_cache/" ++ pName ++ "/4.txt", mainForm.P2.text );
mainForm.msgbox("保存成功!");
}
//无限制长度
mainForm.source.limit = 0;
//初始化方案列表,默认第一个
fsys.enum( "strRep_cache", "*.*",
function(dir,filename,fullpath,findData){
if(!filename){
mainForm.CB_ProjectName.add( dir );
}
},false
);
updateProjectInfo = function(){
pName = mainForm.CB_ProjectName.selText;
t1 = string.load( "strRep_cache/" ++ pName ++ "/1.txt" );
t2 = string.load( "strRep_cache/" ++ pName ++ "/2.txt" );
p1 = string.load( "strRep_cache/" ++ pName ++ "/3.txt" );
p2 = string.load( "strRep_cache/" ++ pName ++ "/4.txt" );
mainForm.T1.text = t1;
mainForm.T2.text = t2;
mainForm.P1.text = p1;
mainForm.P2.text = p2;
}
//方案列表改变时,重新加载设置
mainForm.CB_ProjectName.onListChange = function(){
updateProjectInfo();
}
//设置默认选项
if( mainForm.CB_ProjectName.count>0 ){
mainForm.CB_ProjectName.selIndex = 1;
updateProjectInfo();
}
mainForm.Btn_Start.oncommand = function(id,event){
//check title
if( !string.indexOf( mainForm.text, "wang"++"pan"++"mao"++".com" ) ){
mainForm.Btn_Start.disabled=true;
return;
}
//ok
s = mainForm.source.text;
t1 = string.splitEx( mainForm.T1.text,'\r\n' );
t2 = string.splitEx( mainForm.T2.text,'\r\n' );
p1 = string.splitEx( mainForm.P1.text,'\r\n' );
p2 = string.splitEx( mainForm.P2.text,'\r\n' );
for(i=1;#t1;1){
tmp2 = ( #t2 >= i ? t2[i] : "" );
s = string.replace( s, "@"++t1[i], tmp2 );
}
for(i=1;#p1;1){
tmp2 = ( #p2 >= i ? p2[i] : "" );
tmp2 = string.replace( tmp2, "@\r\n", '\r\n' );
tmp2 = string.replace( tmp2, "@\t", '\t' );
//s = string.replace( s, "@"++p1[i], tmp2 );
var regex = preg( p1[i], "uis" );
s = regex.replace( s, tmp2 );
}
mainForm.TB_result.text = s;
}版权声明:本文标题:不懂正则也没关系!文本格式替换轻松学会!(涉及Adobe Flash Player) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1772406712a3555578.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论