Verbal Expressions for Haxe
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src/expressions
test
.gitignore
.travis.yml
HxVerbalExpressions.hxproj
README.md
build-each.hxml
test-all.hxml
test-cpp.hxml
test-cs.hxml
test-interp.hxml
test-java.hxml
test-js.hxml
test-neko.hxml
test-php.hxml
test-python.hxml
test-swf.hxml

README.md

Haxe VerbalExpressions

Build Status

Haxe Regular Expressions made easy

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.

Getting started

Clone the project or download the sources.

Basic usage of Verbal Expressions is trough new expressions.VerbalExpression():

var myExpression = new expressions.VerbalExpression();

Examples

Testing valid URLs
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
Replacing strings
var result:String = new expressions.VerbalExpression()
    .find("bird")
    .replace("Replace bird with a duck", "duck");
    
trace(result); 
// logs "Replace duck with a duck"

Dependencies

This project has no external dependencies.

Status

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.

API documentation

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.

Contributions

Clone the repo and fork! Pull requests are welcome.

Credits

Thank you to @jehna for coming up with the awesome original idea!