The power of regular expressions without regular expressions.

N

Noman Shapiro

I'm not talking here about the relatively simple, quick and dirty, one-time
regular expressions that you might interactively feed to grep. Rather, I'm
talking about the more complex regular expressions that might appear in your Java programs.

For many of us, regular expressions that are not fairly simple, are an
unreasonable challenge, are effectively "write only" and so are virtually
unmodifiable.

Are you tired of escaping escapes of escapes and of things like

" (.*) (\\d+|@|_)\\[(\\S+)( +)((-?)(\\d+\\.\\d\\d))"

and

"((?:(?:[012]?[0-9]):)?)((?:(?:[0-5]?[0-9]):)?)((?:[0-5]?[0-9]))"


Then try Naomi, a system that gives you the power of regular expressions with
nary a single regular expression.

Here is a fragment of Naomi code:

// Spec is an abstract class.
// Every instance of Spec matches certain strings.

//Matches the string,".*" No need to escape the '.' or the "*"
Spec star=new CharSequenceSpec(".*");

// Matches "p","q","r","s" or "t"
Spec letter=new CharClassSpec(new IntervalCharClass(false,'p','t'));

// Force to match 0 or more instances of "p","q","r","s" or "t"
letter.setMinCount(0); letter.setMaxCount(null); //null means infinity

Spec sharps=new CharSequenceSpec("###");
Spec equal=new CharSequenceSpec("=");
// Matches either "###" or "="
Spec or=new OrSpec(sharps,equal);

// Matches ".*" followed by zero or more instances of
// "p","q","r","s" or "t" followed by either "###" or "="
Spec cat=new ConcatenateSpec(star,letter,or);

Here is another fragment:

enum Suit { spades,hearts,diamonds, clubs};
// Matches "spades","hearts","diamonds" or "clubs"
Spec suit=new EnumSpec(Suit.class);

Naomi is open source.

If you would like to be a beta tester of Naomi, send me an Email.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,979
Messages
2,570,183
Members
46,719
Latest member
login dogas.info

Latest Threads

Top