Skip to content
Simple JavaScript string tokenizer for lexical scanning operations
CoffeeScript JavaScript
Find file
Latest commit c47bb53 Aug 27, 2010 @sstephenson Bump version to 1.0.1
Failed to load latest commit information.
doc Update doc links Aug 23, 2010
lib Add #check and #checkUntil methods Aug 23, 2010
src Fix that scanChar wouldn't scan newlines Aug 27, 2010
test Fix that scanChar wouldn't scan newlines Aug 27, 2010
Cakefile Initial commit Aug 21, 2010
LICENSE MIT license Aug 23, 2010
README.md
package.json Bump version to 1.0.1 Aug 27, 2010

README.md

StringScanner

StringScanner is a simple string tokenizer that provides for lexical scanning operations on a string. It's a JavaScript port of the Ruby library with the same name.

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.

StringScanner is written in CoffeeScript and distributed via npm as a CommonJS module.

Quick start

$ npm install strscan
$ node-repl
> var StringScanner = require("strscan").StringScanner
> var s = new StringScanner("This is a test")
> s.scan(/\w+/)             # => "This"
> s.scan(/\w+/)             # => null
> s.scan(/\s+/)             # => " "
> s.scan(/\s+/)             # => null
> s.scan(/\w+/)             # => "is"
> s.hasTerminated()         # => false
> s.scan(/\s+/)             # => " "
> s.scan(/(\w+)\s+(\w+)/)   # => "a test"
> s.getMatch()              # => "a test"
> s.getCapture(0)           # => "a"
> s.getCapture(1)           # => "test"
> s.hasTerminated()         # => true

More

Clone, fork, or file bugs at GitHub

Read the full documentation/annotated source code

Copyright

Copyright (c) 2010 Sam Stephenson. Distributed under the terms of an MIT-style license. See LICENSE for details.

Something went wrong with that request. Please try again.