/** * 根据输入的正则表达式,提取与之匹配的字符串,并新建一个文档显示所有匹配的字符串, * 显示时每个匹配项占一行 * * @author Guapo * @version v1.0 */ function getText() { var _regex=prompt("this program is for extracting strings using a regular expression,please input a regular expression",""); if(_regex==""||_regex==null) { alert("you have typed nothing"); return; } var regex=new RegExp(_regex,"gim"); document.selection.SelectAll(); var textInCurrentDocument=document.selection.Text; var matchResultArray=textInCurrentDocument.match(regex); if(matchResultArray) { var len=matchResultArray.length; editor.NewFile(); for(var i=0;i=两个的相连空格替换成一个,只支持英文半角空格 * * @author Guapo * @version v1.0 */ function replace2MoreBlank() { document.selection.Replace(" {2,}"," ",eeFindNext | eeReplaceAll | eeFindReplaceRegExp); } /** * 将当前正在编辑文档中的所有>=两个的相连空行替换成一个 * * @author Guapo * @version v1.0 */ function replace2MoreNewLine() { return; } /** * 为当前正在编辑文档中的所有行的行首添加特定的字符串 * * @author Guapo * @version v1.0 */ function addString2LineStart() { var s=prompt("what string do you want to add to start of line?","input the string here"); if(s==""||s==null) { return; } var t="\\0"; document.selection.Replace("(^.)|(^\\n)",s+t,eeFindNext | eeReplaceAll | eeFindReplaceRegExp); document.HighlightFind=false; } /** * 为当前正在编辑文档中的所有行的行尾添加特定的字符串 * * @author Guapo * @version v1.0 */ function addString2LineEnd() { var s=prompt("what string do you want to add to end of line?","input the string here"); if(s==""||s==null) { return; } var t="\\0"; document.selection.Replace("(.$)|(^\\n$)",t+s,eeFindNext | eeReplaceAll | eeFindReplaceRegExp); document.HighlightFind=false; } function isN(s) { if(s==null||s=="") { return false; } var array=s.match(/\d+/); if(array) { if(s==array[0]) { return true; } else { return false; } } else { return false; } } mainMenu=CreatePopupMenu(); mainMenu.Add("copy the path(exclude the name and extention)",1); mainMenu.Add("copy the full name(include path)",2); mainMenu.Add( "", 0, eeMenuSeparator ); mainMenu.Add("using regex to extract string",3); mainMenu.Add( "", 0, eeMenuSeparator ); mainMenu.Add("delete all white spaces at the beginning of the line",4); mainMenu.Add("delete all white spaces at the end of the line",5); mainMenu.Add("add n white spaces to the start of the line",6); mainMenu.Add("add n white spaces to the end of the line",7); mainMenu.Add( "", 0, eeMenuSeparator ); mainMenu.Add("merge two or more white spaces to one",8); mainMenu.Add("merge two or more blank line to one",9); mainMenu.Add( "", 0, eeMenuSeparator ); mainMenu.Add("add a string to the start of the line",10); mainMenu.Add("add a string to the end of the line",11); mainMenu.Add( "", 0, eeMenuSeparator ); mainMenu.Add("about",100); var witchItem=mainMenu.Track(); switch(witchItem) { case 1: copyPath(); break; case 2: copyFullName() break; case 3: getText(); break; case 4: deleteLineStartBlank(); break; case 5: deleteLineEndBlank(); break; case 6: addBlank2LineStart(); break; case 7: addBlank2LineEnd(); break; case 8: replace2MoreBlank(); break; case 9: replace2MoreNewLine(); break; case 10: addString2LineStart(); break; case 11: addString2LineEnd(); break; case 100: alert("If you like to translate,please contact me!Thank you!\n\nAuthor:Guapo\nEmail:yangshuai@gmail.com"); break; default: break; }