Skip to content
Newer
Older
100644 44 lines (33 sloc) 1.58 KB
28353e5 @sstephenson Add readme
authored
1 ## StringScanner
2
3 **StringScanner** is a simple string tokenizer that provides for lexical
4 scanning operations on a string. It's a JavaScript port of the [Ruby
5 library with the same name](http://ruby-doc.org/core/classes/StringScanner.html).
6
7 Scanning a string means keeping track of and advancing a position (a
8 zero-based index into the source string) and matching regular expressions
9 against the portion of the source string after the position.
10
11 StringScanner is written in [CoffeeScript](http://coffeescript.org/) and
12 distributed via [npm](http://npm.mape.me/) as a [CommonJS
13 module](http://www.commonjs.org/).
14
15 ### Quick start
16
17 $ npm install strscan
18 $ node-repl
19 > var StringScanner = require("strscan").StringScanner
20 > var s = new StringScanner("This is a test")
21 > s.scan(/\w+/) # => "This"
22 > s.scan(/\w+/) # => null
23 > s.scan(/\s+/) # => " "
24 > s.scan(/\s+/) # => null
25 > s.scan(/\w+/) # => "is"
26 > s.hasTerminated() # => false
27 > s.scan(/\s+/) # => " "
28 > s.scan(/(\w+)\s+(\w+)/) # => "a test"
29 > s.getMatch() # => "a test"
30 > s.getCapture(0) # => "a"
31 > s.getCapture(1) # => "test"
32 > s.hasTerminated() # => true
33
34 ### More
35
3962e97 @sstephenson Update doc links
authored
36 [Clone, fork, or file bugs at GitHub](http://github.com/sstephenson/strscan-js)
37
38 [Read the full documentation/annotated source code](http://sstephenson.github.com/strscan-js/)
28353e5 @sstephenson Add readme
authored
39
40 ### Copyright
41
42 Copyright (c) 2010 Sam Stephenson. Distributed under the terms of an
43 MIT-style license. See LICENSE for details.
Something went wrong with that request. Please try again.