Retrieve RegEx Pattern From A EReg Insance As A String

59 views
Skip to first unread message

AlienCoder

unread,
Apr 11, 2016, 12:10:41 PM4/11/16
to Haxe
Hello Community,

is it possible to return the regEx pattern string of an EReg object once it is instanced?

To become more concrete:

I am resolving a string that consists of integers seperated by one or many none-word-character(s).

var regEx : EReg = ~/([0-9]+)(\W+[0-9]+)+/;
var string = "33#44#22#31";


This is just a radical simplification. The regular expression check in my code is a little more complex. And there are different checks to be done. To keep the procedure a little more simple I would like to re-use the regEx pattern and complement it with some additional regEx statements.

It seems the EReg api has no method for that purpose.

So, is it possible to get the part "([0-9]+)(\W+[0-9]+)+" from the regEx instance as a string?

Kind regards
Michael

Clark Jones

unread,
Apr 11, 2016, 1:34:49 PM4/11/16
to Haxe
From what I can tell there is a private var `r` that you could use @:access with and use toString() to get the value, I'm thinking this is private for a  reason and might not exist on every target. I had a similar problem in the past and just ended up storing the string and creating the regex through the constructor when it was needed. 
Message has been deleted

Alexander Kuzmenko

unread,
Apr 11, 2016, 5:26:41 PM4/11/16
to Haxe
Here is what i was able to acheive in extracting regex from EReg instance on all Haxe targets: https://github.com/RealyUniqueName/HUnit/blob/master/src/hunit/match/ERegMatch.hx#L56

понедельник, 11 апреля 2016 г., 19:10:41 UTC+3 пользователь AlienCoder написал:
Message has been deleted

AlienCoder

unread,
Apr 12, 2016, 4:00:54 AM4/12/16
to Haxe
Hello Alexander, hello Clark,

your answers are both worth beeing considered. You helped me a lot.
Thank you very much.

Kind regards
Michael
Reply all
Reply to author
Forward
0 new messages