Skip to content

Latest commit

 

History

History
90 lines (63 loc) · 2.27 KB

README.md

File metadata and controls

90 lines (63 loc) · 2.27 KB

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!