Create a gist now

Instantly share code, notes, and snippets.

@mas3 /renum.js
Created Mar 21, 2013

Embed
What would you like to do?
連番付け替え(「スクリプト実行」用スクリプト)
/*
* 連番付け替え
*
* (before)
* 1. aaa
* 2. bbb
* 2. ccc
*
* (after)
* 1. aaa
* 2. bbb
* 3. ccc
*
* 「スクリプト実行」用スクリプト
* http://books.ivory.ne.jp/execscript/
*/
var lines = data.split("\n");
var outdata = new Array();
var count = 1;
for (var i = 0; i < lines.length; i++) {
var line = lines[i];
if (line.match(/^[0-9]+\./)) {
line = line.replace(/^[0-9]+/, count);
count = count + 1;
}
outdata.push(line);
}
return outdata.join("\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment