Created
June 10, 2009 19:09
-
-
Save slaskis/127421 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage example: | |
var r = new Regex( ~/<%(.*?)%>/sm ); | |
for( m in r.match( str ) ) | |
trace( "Inside tags: " + m[1] + ", Entire match: " + m[0] ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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