@@ -20,6 +20,10 @@
php/php7: fixed accessing enum constructors on enum type stored to a variable (#6159)
php: fix invoking functions stored in dynamic static vars (#6158)
+ Standard Library:
+
+ all : added EReg.escape
2017-03-20: 3.4.2
Bugfixes:
@@ -192,4 +192,13 @@ class EReg {
public function map( s : String, f : EReg -> String ) : String {
return null;
}
+ /**
+ Escape the string `s` for use as a part of regular expression.
+ If `s` is null, the result is unspecified.
+ **/
+ public static function escape( s : String ) : String {
+ return null;
+ }
@@ -173,6 +173,10 @@
return buf.toString();
+ return escapeRegExpRe.map(s, function(r) return "\\" + r.matched(0));
+ static var escapeRegExpRe = ~/[\[\]{}()*+?.\\\^$|]/g;
@:extern @:native("_hx_regexp_new_options")
static function _hx_regexp_new_options(s:String, options:String) : Dynamic return null;
@@ -130,4 +130,8 @@ import cs.system.text.regularexpressions.*;
buf.add(s.substr(offset));
+ public static inline function escape( s : String ) : String {
+ return Regex.Escape(s);
@@ -112,4 +112,9 @@
+ return (cast s).replace(escapeRe, "\\$&");
+ static var escapeRe = new flash.utils.RegExp("[.*+?^${}()|[\\]\\\\]", "g");
@@ -183,6 +183,10 @@ private typedef ERegValue = hl.Abstract<"ereg">;
@:hlNative("std", "regexp_new_options") static function regexp_new_options( bytes : hl.Bytes, options : hl.Bytes ) : ERegValue {
@@ -177,4 +177,8 @@ import java.util.regex.*;
+ return Pattern.quote(s);
@@ -108,6 +108,11 @@
+ static var escapeRe = new js.RegExp("[.*+?^${}()|[\\]\\\\]", "g");
@:native("RegExp")
@@ -154,6 +154,11 @@ class EReg {
static function __init__() : Void {
if (Rex == null){
throw "Rex is missing. Please install lrexlib-pcre.";
@@ -197,6 +197,11 @@
static var regexp_new_options = neko.Lib.load("regexp","regexp_new_options",2);
static var regexp_match = neko.Lib.load("regexp","regexp_match",4);
static var regexp_matched = neko.Lib.load("regexp","regexp_matched",2);
@@ -118,4 +118,8 @@
+ return untyped __call__("preg_quote", s);
@@ -757,6 +757,11 @@ extern class Global {
**/
static function preg_match_all( pattern:String, subject:String, ?matches:NativeArray, ?flags:Int, ?offset:Int ) : EitherType<Bool,Int> ;
+ @see http://php.net/manual/en/function.preg-quote.php
+ static function preg_quote( str:String, ?delimiter:String ) : String;
/**
@see http://php.net/manual/en/function.preg-split.php
@@ -134,4 +134,8 @@ import php.*;
+ return Global.preg_quote(s);
@@ -168,4 +168,8 @@ class EReg {
+ return Re.escape(s);
@@ -199,7 +199,7 @@ extern class Re
public static function subn(pattern:Pattern, repl:Repl, string:String, count:Int=0, flags:Int=0):String;
- public static function escape(string:String):TODO;
+ public static function escape(string:String):String;
public static function purge():Void;
@@ -107,3 +107,6 @@ pos.len == 2;
~/(Hello)/.map("Hello", function(e) return "Hallo") == "Hallo";
~/(World)/.map("Hello World", function(e) return "Hallo") == "Hello Hallo";
~/(Hola)/.map("Hello World", function(e) return throw "not called") == "Hello World";
+// escape
+new EReg("^" + EReg.escape("\\ ^ $ * + ? . ( ) | { } [ ]") + "$", "").match("\\ ^ $ * + ? . ( ) | { } [ ]") == true;