OutputBar.Clear(); OutputBar.writeln("EmEdit ver. " + editor.Version); OutputBar.Visible = true; OutputBar.SetFocus(); function trim(text) { return (text || "").replace(/^\s+|\s+$/g, ""); } function work(str) { arr0 = str.split(/(>|<)/); ret = '<' + arr0[0] + '>'; // <p id="P7"> arr_authors = arr0[1].split(";"); for (i = 0; i < arr_authors.length; i++) { arr_name = trim(arr_authors[i]).split(","); arrLength = arr_name.length; if (arrLength == 1) { ret += arr_name[0]; break; } if (arrLength == 3) { ret += trim(arr_name[1]) + ' ' + trim(arr_name[2]) + ' ' + trim(arr_name[0]) + ', '; } else if (arrLength == 2) { ret += trim(arr_name[1]) + ' ' + trim(arr_name[0]) + ', '; } } ret = trim(ret); if (ret.lastIndexOf(',') == ret.length-1){ ret = ret.substring(0, ret.length-2) } return ret + '<'; } while (document.selection.Find("<p id=\"P7\">.+?<", eeFindNext | eeFindReplaceRegExp, eeExFindRegexBoost)) { OutputBar.writeln(document.selection.Text); out = work(document.selection.Text); OutputBar.writeln(out + '\n'); document.selection.Text = out; } |