Code Monkey home page Code Monkey logo

string-scanner's Introduction

string-scanner

scan through strings. supports forwards and backwards scanning.

Installation

In node.js:

$ npm install string-scanner

In the browser (with component):

$ component install matthewmueller/string-scanner

API

scanner(str, [offset])

Initialize a scanner for str at the given offset. If no offset is given, default to 0.

var s = scanner('apples, peaches, kiwis', 12);

scanner.next(expr, [n])

Scan for the next expr. expr can either be a string or a regex. Return the nth match. n defaults to 1, or the first match.

s.next(/apples?/) // apples
s.next('peaches') // peaches

scanner.prev(expr, [n]), scanner.previous(expr, [n])

Scan for the previous expr. expr can either be a string or a regex. Return the nth match. n defaults to 1, or the first match.

s.last()
s.prev(/kiwis?/) // kiwis
s.prev('peaches') // peaches

scanner.match()

Return the current match. Useful for regex captures. If no match is found, this function returns null.

s.next(/apples?/)
 .match()

scanner.peak(expr, [n])

Peak forward or backwards n matches in search of expr. Peaking does not change the offset.

s.peak(/\w+/, 2) // peaches
s.next(/\w+/, 2) // peaches

scanner.cursor([i])

Get or set the cursor within the string.

scanner.last()

Move the cursor to the end of the string

scanner.first()

Move the cursor to the beginning of the string

Test

npm install component-test
make test

License

MIT

string-scanner's People

Contributors

matthewmueller avatar

Stargazers

 avatar Zoltan Kochan avatar Po-Ying Chen avatar  avatar Harri Siirak avatar Daniel Doblado avatar Nazeeruddin Ikram avatar Erick Belfort avatar Tyler Larson avatar Neal Shyam avatar Ben McMahen avatar Jonas Hermsmeier avatar  avatar Azer Koçulu avatar stagas avatar Lance Pollard avatar 迁移到 leogiese avatar Simon Boudrias avatar Sascha avatar Sindre Sorhus avatar

Watchers

James Cloos avatar  avatar

Forkers

retrofox

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.