Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
579 B

4 years ago
var regex = /sed|ipsum/g;
var text = require("fs").readFileSync("example.txt");
var LineCounter = require("../");
var counter = new LineCounter(text);
var match;
while ((match = regex.exec(text)) !== null) {
// Example for .countUpTo()
console.log(
"Found '" + match[0] + "'",
"at index", match.index,
"which is in line ", counter.countUpTo(match.index)
);
// Example for .locate()
console.log(
"Found '" + match[0] + "'",
"at index", match.index,
"which is at location", counter.locate(match.index)
);
}