You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Features needed

  • Supports matching against binary data (not just character data)
  • Implements POSIX longest leftmost match algorithm
  • Uses non-backtracking algorithm to avoid exponential worst-time behavior

Survey of Java regular expression libraries

LibraryAlgorithmPOSIX longest leftmost matchLicenseURL
java.util.regexBacktrackingNoJava (included as part of Java)
Jakarta OROBacktrackingNoApachehttp://jakarta.apache.org/oro/
Jakarta RegexBacktrackingNoApachehttp://jakarta.apache.org/regexp/
com.stevesoft.patBacktrackingUnknownLGPLhttp://www.javaregex.com/home.html
dk.brics.automatonDFAUnknownBSDhttp://www.brics.dk/automaton/index.html
JRegexBacktrackingUnknownBSDhttp://jregex.sourceforge.net/

Of these, the automaton library looks the most interesting from a DFA perspective.

No POSIX longest match regex library for java/scala (as far as we can tell)

Notes for implementing our own regular expression engine

  • Someone started a binary parser and pickler combinator library.  https://github.com/teigen/byteme  Still looks immature, but might provide some good ideas.

  • I started a Scala implementation of a regular expression language specific to XML Schema last year.  It uses the automaton classes in scala.util.automata.  It's a really basic implementation, but I'd be happy to contribute it.  The automata classes in particular are not specific to characters, so they could be adapted to match binary data instead.  --Jonathan Cranford

Miscellaneous notes:

java scanner - takes Readable as input (good), doesn't allow regex that matches at beginning of stream.


Implement longest match by rotating through mulitiple regex matchers, which determine if the pattern matches immediately at the beginning of the supplied characters.

Java regex Matcher class takes only CharSequence as input.

CharSequence is finite (has length() method) which precludes (most likely) creating a virtualized stream-like behavior underneath our own CharSequence implementation.

---------------------

Scala ||| combinator of regex parsers produces longest match to the combined regex's.

Scala combinator parsers read from a Reader.

The reader can virtualize the character stream up until a decode error, or size limit of our choice, and can hide all details of when additional blocks of data must be retrieved.

val rdr = new InputStreamReader(Channels.newInputStream(rbc : ReadableByteChannel)

// Must figure out what happens if character decoding gets an error.
// Worst case, we have to implement Reader interface ourselves with code that calls the decoder.

// length limit on delimiter match could be implemented by creating a finites substream from the rbc, instead of just handing the original rbc to it.

val pr = Parser.parse(rdr)

  • No labels