SARE
Simple API for Regular Expressions: event-based matching, where each capture group gets a handler.
2012–2013Java
Java's regular expression API hands you a Matcher and leaves you to walk it — loop, ask which group you are in, pull the text out, branch. SARE inverts that the way SAX inverts XML parsing: you attach an action to a group, and the parser calls it as the match runs.
String regex = "([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)";
RegexParser sare = new RegexParser(regex);
ConsoleOut co = new ConsoleOut();
sare.assignAction(0, co);
sare.assignAction(1, co);
sare.assignAction(2, co);
sare.assignAction(3, co);
sare.assignAction(4, co);
sare.process("192.255.255.150");Implement IGroupAction, assign it to the groups you care about, and the work happens as the parse proceeds rather than after it. It suits extraction over long input, where holding the whole match is wasteful; for a single test of a short string the standard API is simpler and this is more machinery than the job needs.