A simple, fast string tokenizer for lexical scanning operations.
PStringScanner is a simple string tokenizer that provides for lexical scanning operations on a string.
The original Ruby version was written in C, and is very fast. This version, while not in C, is as fast on short strings (under 32 Kb of characters), and almost twice as fast on large strings (million+ characters) than the other ports.
npm install -g pstrscan
Scanning a string means keeping track of and advancing a position (a zero-based index into the source string) and matching regular expressions against the portion of the source string after the position.
var PStrScan = require"pstrscan";var s = "This is a test";sscan/\w+/; // = "This"sscan/\w+/; // = nullsscan/\s+/; // = " "sscan/\s+/; // = nullsscan/\w+/; // = "is"shasTerminated; // = falsesscan/\s+/; // = " "sscan/\s+/; // = "a test"sgetMatch; // = "a test"sgetCapture1; // = "a"sgetCapture2; // = "test"shasTerminated; // = true