VerbalExpressions is a Haxe library that helps to construct difficult regular expressions. Ported from the awesome JavaScript VerbalExpressions. This project wraps around the Haxe EReg class.
Clone the project or download the sources.
Basic usage of Verbal Expressions is trough new expressions.VerbalExpression()
:
var myExpression = new expressions.VerbalExpression();
var expression = new expressions.VerbalExpression()
.startOfLine()
.then("http")
.maybe("s")
.then("://")
.maybe("www.")
.anythingBut(" ")
.endOfLine();
var url = "https://www.haxe.org/";
// test if the url matches
if (expression.isMatch(url)) {
trace('$url is a valid URL');
} else {
trace('$url is an invalid URL');
}
trace(expression.toString());
// logs the regular expression source: ^(http)(s)?(://)(www.)?([^{ }]*)$
expression.toRegex();
// the Haxe EReg instance
var result:String = new expressions.VerbalExpression()
.find("bird")
.replace("Replace bird with a duck", "duck");
trace(result);
// logs "Replace duck with a duck"
This project has no external dependencies.
Haxe target | status |
---|---|
Haxe interpreter | works |
C++ | works |
C# | works |
Java | compiles but has errors |
JavaScript | works |
Neko | works |
PHP | works |
Python | works |
Flash | works |
Note: Haxe is awesome! One codebase, many targets, no platform specific code.
You can find the documentation for the original JavaScript repo on their wiki. There can be some differences in the methods, but in general this documentation will cover most functions.
Clone the repo and fork! Pull requests are welcome.
Thank you to @jehna for coming up with the awesome original idea!