Skip to content

Instantly share code, notes, and snippets.

@slaskis
Created June 10, 2009 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slaskis/127421 to your computer and use it in GitHub Desktop.
Save slaskis/127421 to your computer and use it in GitHub Desktop.
// Usage example:
var r = new Regex( ~/<%(.*?)%>/sm );
for( m in r.match( str ) )
trace( "Inside tags: " + m[1] + ", Entire match: " + m[0] );
class Regex {
var exp : EReg;
var str : String;
public function new( r : EReg ) {
exp = r;
}
public function match( s : String ) {
str = s;
return this;
}
public function matchedLeft() {
return exp.matchedLeft();
}
public function matchedRight() {
return exp.matchedRight();
}
public function hasNext() {
return exp.match( str );
}
public function next() {
var match = new Array<String>();
var i = 0, m = exp.matched( i );
while( m != null ) {
match[i] = m;
m = exp.matched( ++i );
}
str = exp.matchedRight();
return match;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment