Q:

Using RegExp for separate each five-character by '-' or something

Hello i have a TextField on my scene. It haves only digits, user input them by clicking on buttons (NumPad). I want to separate each five-character by '-' . User must input 20 digits
I'm using this code
var rexp:RegExp  = new RegExp("/^((\d{0,5})(\d{0,5})(\d{0,5})(\d{0,5}))$/"); 
trace(rexp.test(textEnter.text)); //always false
var s:String=textEnter.text.replace(rexp, "$2-$3-$4-$5"); 
trace(s);//format is fails
textEnter.text = s;

On this site my patterns are working fine. But they aren't working in my AS3 script.
can you help me and say what i'm doing wrong.

A:

There are two ways to instantiate a regex in AS3.  You can either use the constructor form or the regex literal form.
Literal form
With this notation, the regex literal creates an implicit regex object, so you don't have to.  The following works fine:
var rexp:RegExp = /^((\d{0,5})(\d{0,5})(\d{0,5})(\d{0,5}))$/;

Constructor form
If you really want to use the constructor form to instantiate your regex, then you replace the delimiting forward slashes with quotation marks.  You must also add a second backslash to any metasequences.
var rexp:RegExp  = new RegExp("^((\\d{0,5})(\\d{0,5})(\\d{0,5})(\\d{0,5}))$"); 

More info: http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e92.html

