emeditor 正则表达式找出1-3个任意字符的行

浪子不回头ぞ 提交于 2019-11-27 10:55:06

查找替换:

^.{1,3}$

****以下前七行符合条件


.
1
12
147
下行
上行一
FRRRRR
今天收获

**************以上前七行符合条件

宏语句【关键点:整理交通格式、一键排版】:

menu= CreatePopupMenu();//鸿蒙20190815 精简,只取最常用的语句
排版 = CreatePopupMenu();
特殊文本清理 = CreatePopupMenu();
cmd = CreatePopupMenu();

if (document.selection.isempty)
  nFlags=eeFindNext | eeReplaceAll | eeFindReplaceRegExp;
  else
  nFlags=eeFindNext | eeReplaceSelOnly | eeReplaceAll | eeFindReplaceRegExp;

menu.Add( "鸿蒙20190815", 1 );
menu.AddPopup( "特殊文本清理", 特殊文本清理 );
特殊文本清理.Add( "整理交通卡口", 2);


menu.AddPopup( "排版", 排版 );
排版.Add( "一键排版:行首加2个全角空格,删除空行(含空格)、部章后冒号删除、书名、标题(含章节、序、前言、后记、尾声 )前加2空行。规范中文引、破折号", 22);
排版.Add( "删除硬回车(硬回车即换行符前有一个半角空格)", 23 );
排版.Add( "★段落重排(修正句内换行,句首标点,统一章节间行)2009.08", 24 );
排版.Add( "段落间加空行", 25 );
排版.Add( "2个以上空行变二空行", 26 );//


result = menu.Track( 0 );
switch(result){
case 1:
alert("鸿蒙20190815:)");
break;
case 2://整理交通卡口:下行\r\n\d+\r\n\d+\r\n ==正则表达式的替换语句==》宏语句==下行\\r\\n\\d+\\r\\n\\d+\\r\\n
//document.selection.Replace("下行\\r\\n\\d+\\r\\n\\d+\\r\\n","",eeFindNext|eeReplaceAll|eeFindReplaceRegExp);//删除下行及之后的两行数字【可行】
document.selection.Replace("^\.\{1,3\}$","",eeFindNext|eeReplaceAll|eeFindReplaceRegExp);//删除1-3个任意字符的行 【可行--20190815】
//document.selection.Replace("^下行$","",eeFindNext|eeReplaceAll|eeFindReplaceRegExp);////删除顶格的字符:下行【可行】
//document.selection.Replace("^\\d{1,3}$","",eeFindNext|eeReplaceAll|eeFindReplaceRegExp);//删除顶格的1-3位数字【可行】
break;


case 23: //删除硬回车
bAnswer = confirm("这里处理的硬回车是指“句末回车前有一个半角空格”。\n不符合这种情况的,请使用“段落重排”。\n\n按确定:“上一句句末有空格,下一句顶格,句首没有空格”\n\n按取消:“上一句句末有空格,下一句句首也有多个半角空格”");
document.selection.Replace("([。?!]) \\n","\\1\\n",nFlags);
document.selection.Replace("^([0-9一二三四五六七八九十两百零〇—].+) \\n","\\1\\n",nFlags);
if (bAnswer==true)
{
document.selection.Replace("[  ]+\\n([^  ])","\\1",nFlags);
}
else
{
document.selection.Replace("^[ ]+","",nFlags);
document.selection.Replace("[  ]+\\n([^ ])","\\1",nFlags);
}
break;

case 24: //段落重排(修正句内换行,句首标点,统一章节间行)
document.selection.Replace("^[  ]+$","",nFlags);
document.selection.Replace("^\\t+","\\n\\n  ",nFlags);
document.selection.Replace("   ","  ",nFlags);
document.selection.Replace("([^  ])  ","\\1\\n  ",nFlags);
document.selection.Replace("(^[  ]+)|([  ]+$)","",nFlags);//去首尾空格
var title=prompt("输标题表达式(已含作品相关序楔正文前言后记),保护原有分段格式。","第[0-9一二三四五六七八九十两百零〇]{1,5}[册集部卷章篇节回]")
if (title!="")
{
document.selection.Replace("^(作品相关.*)$","【标记3】\\1【标记4】",nFlags);
document.selection.Replace("^(正文.*)$","【标记3】\\1【标记4】",nFlags);
document.selection.Replace("^(序.*)$","【标记3】\\1【标记4】",nFlags);
document.selection.Replace("^(前言.*)$","【标记3】\\1【标记4】",nFlags);
document.selection.Replace("^(后记.*)$","【标记3】\\1【标记4】",nFlags);
document.selection.Replace("^(楔.*)$","【标记3】\\1【标记4】",nFlags);
document.selection.Replace("^(引子.*)$","【标记3】\\1【标记4】",nFlags);
document.selection.Replace("^(公告.*)$","【标记3】\\1【标记4】",nFlags);
document.selection.Replace("^(凑字数.*)$","【标记3】\\1【标记4】",nFlags);
document.selection.Replace("^(.*"+title+".*)$","【标记3】\\1【标记4】",nFlags);
document.selection.Replace("^\\n","",nFlags);
}
//去除多余标点
document.selection.Replace("[。…=\\.]{2,}","……",nFlags);
bAnswer = confirm("按确定,合并不在同一行的引号括号,错误的分段。\n\n按取消,没有错误的标点分段。");
if (bAnswer==true)
{
document.selection.Replace("([,。:?!…”)》—])[,。:?!)》]+","\\1",nFlags);
document.selection.Replace("([^。?!…])\\n([^ ※#*…。.\\-\\.])","\\1\\2",nFlags);//取消非标点结尾换行
document.selection.Replace("([“「][^”」]+)\\n([^“「]+[”」])","\\1\\2\\n",nFlags);
document.selection.Replace("(([^)]+)\\n([^(]+))","\\1\\2\\n",nFlags);
document.selection.Replace("([,。:?!…”)》—][”」])","\\1\\n",nFlags);
document.selection.Replace("([:。?!…”])\\n\\n","\\1\\n",nFlags);
document.selection.Replace("\\n([,。:?!…”;)】》—.’」])","\\1",nFlags);//句首标点
}
document.selection.Replace("^([^  ])","  \\1",nFlags);//行首加空格
document.selection.Replace("^[  ]+","  ",nFlags);
//恢复原有分段格式
document.selection.Replace("【标记4】【标记3】","【标记4】\\n\\n\\n【标记3】",nFlags);
document.selection.Replace("【标记3】(.+)【标记4】","\\n\\n\\n\\1\\n  ",nFlags);
document.selection.Replace("【标记3】","\\n\\n\\n",nFlags);
document.selection.Replace("【标记4】","\\n  ",nFlags);
//给行首加2个全角空格,并删除多余空行。
document.selection.Replace("^[  ]+$","",nFlags);
document.selection.Replace("^[\\t]+","",nFlags);
document.selection.Replace("^([^  《])","  \\1",nFlags);
document.selection.Replace("(第[0-9一二三四五六七八九十两百零〇]{1,5}[册集部卷章篇节回].*)\\n\\n\\n","\\1\\n",nFlags);
document.selection.Replace("^([  ]+[《第正作序楔引前后上0-9一二三四五六七八九十两百零〇])","\\n\\n\\1",nFlags);
document.selection.Replace("^([  ]+[^  ]+第[0-9一二三四五六七八九十两百零〇]{1,5}[册集部卷章篇节回])","\\n\\n\\1",nFlags);
document.selection.Replace("([^  ])\\n\\n  ","\\1\\n  ",nFlags);
document.selection.Replace("^[  ]{3,}","  ",nFlags);
document.selection.Replace("^\\n\\n\\n","\\n\\n",nFlags);
document.selection.Replace("^\\n\\n\\n","\\n\\n",nFlags);
document.selection.Replace("^\\n\\n\\n","\\n\\n",nFlags);
break;

case 25: //段落加空行
document.selection.Replace("$","\\n",nFlags);
document.selection.Replace("^\\n\\n\\n","\\n\\n",nFlags);
document.selection.Replace("^\\n\\n\\n\\n","\\n\\n",nFlags);
document.selection.Replace("^\\n\\n\\n\\n\\n","\\n\\n",nFlags);
break;
case 26: //2个以上空行变二空行
document.selection.Replace("^\\n\\n\\n","\\n\\n",nFlags);
document.selection.Replace("^\\n\\n\\n\\n","\\n\\n",nFlags);
document.selection.Replace("^\\n\\n\\n\\n\\n","\\n\\n",nFlags);
break;

case 22: //一键排版:行首加2个全角空格,删除空行(含空格)、部章后冒号删除、标题(含章节、序、前言、后记、尾声 )前加2空行。规范中文引、破折号.
document.selection.Replace("^[\\t]+","",nFlags);
document.selection.Replace("[\\t]+"," ",nFlags);
document.selection.Replace("^[  ]+","",nFlags);
document.selection.Replace("[  ]+$","",nFlags);
document.selection.Replace("^([^  ])","  \\1",nFlags);
document.selection.Replace("^[  \t]*\\n","",nFlags);
document.selection.Replace("[   ]+$","",nFlags);
document.selection.Replace("部+\:","部 ",nFlags);
document.selection.Replace("章+\:","章 ",nFlags);
document.selection.Replace("([^ ]+)卷首+$","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)封面欣赏+$","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)文本来源+$","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)导语+$","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)内容简介+$","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)编辑推荐+$","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)作者简介+$","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)精彩书评+$","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)题记+$","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)附录+$","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)本卷主线+$","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)注释+$","\\n\\n\\0",nFlags);
//短句无标点,当标题,空二行.---此行视文本情况关闭使用,如诗歌类。
//document.selection.Replace("^\\s\\s\\w{1,15}$","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)前言+$","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)前言 +.{1,12}","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)楔子+$","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)楔子 +.{1,12}","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)楔+$","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)楔 +.{1,12}","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)序+$","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)序 +.{1,12}","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)序言+$","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)序言 +.{1,12}","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)序章+$","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)序章 +.{1,12}","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)正文+$","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)后记+$","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)后记 +.{1,12}","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)尾声+$","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)尾声 +.{1,12}","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)番外 +.{1,12}","\\n\\n\\0",nFlags);
document.selection.Replace("^卷首+$","\\n\\n\\0",nFlags);
document.selection.Replace("^内容简介+$","\\n\\n\\0",nFlags);
document.selection.Replace("^前言+[$ .{1,12}]","\\n\\n\\0",nFlags);
document.selection.Replace("^前言 +.{1,12}","\\n\\n\\0",nFlags);
document.selection.Replace("^楔子+$","\\n\\n\\0",nFlags);
document.selection.Replace("^楔子 +.{1,12}","\\n\\n\\0",nFlags);
document.selection.Replace("^楔+$","\\n\\n\\0",nFlags);
document.selection.Replace("^楔 +.{1,12}","\\n\\n\\0",nFlags);
document.selection.Replace("^序+$","\\n\\n\\0",nFlags);
document.selection.Replace("^序言+$","\\n\\n\\0",nFlags);
document.selection.Replace("^正文+$","\\n\\n\\0",nFlags);
document.selection.Replace("^后记+$","\\n\\n\\0",nFlags);
document.selection.Replace("^尾声+$","\\n\\n\\0",nFlags);
document.selection.Replace("^番外+$","\\n\\n\\0",nFlags);
//顶格的书名,其后为换行符,加2空行
document.selection.Replace("^\\s\\s《\.+》$","\\n\\n\\0",nFlags);
//上中下卷前,加2空行
document.selection.Replace("(([^ ]+)[上中下]卷)+$","\\n\\n\\1",nFlags);
document.selection.Replace("(([^ ]+)[上中下]卷) +.{1,12}","\\n\\n\\0",nFlags);

document.selection.Replace("(([^ ]+)卷[0-9一二三四五六七八九十两百零〇]{1,5})+$","\\n\\n\\1",nFlags);
document.selection.Replace("(([^ ]+)卷[0-9一二三四五六七八九十两百零〇]{1,5}) +.{1,12}","\\n\\n\\0",nFlags);
document.selection.Replace("^第[0-9一二三四五六七八九十两百零〇]{1,5}[册集部卷章节回篇折]+$","\\n\\n\\0",nFlags);
document.selection.Replace("^第[0-9一二三四五六七八九十两百零〇]{1,5}[册集部卷章节回篇折] +.{1,12}","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)第[0-9一二三四五六七八九十两百零〇]{1,5}[册集部卷章节回篇折]+$","\\n\\n\\0",nFlags);
document.selection.Replace("([^ ]+)第[0-9一二三四五六七八九十两百零〇]{1,5}[册集部卷章节回篇折] +.{1,12}","\\n\\n\\0",nFlags);
//以下规范中文引、破折号、3个以上空行改2空行
document.selection.Replace("──","——",nFlags);
document.selection.Replace("[「『]","“",nFlags);
document.selection.Replace("[」』]","”",nFlags);
document.selection.Replace("^[  ]+$","",nFlags);
document.selection.Replace("^[\\t]+$","",nFlags);
document.selection.Replace("^\\n\\n","【标记】",nFlags);
document.selection.Replace("^\\n","",nFlags);
document.selection.Replace("【标记】\\n","【标记】",nFlags);
document.selection.Replace("(【标记】)+","【标记】",nFlags);
document.selection.Replace("【标记】","\\n\\n\\n",nFlags);
document.selection.Replace("^\\n\\n\\n","\\n\\n",nFlags);
break;
default:
}

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!