4 Replies Latest reply on Sep 2, 2009 7:12 PM by lee704

    How to display regular expression text

    lee704 Level 1

      I cannot seem to get the text of a regular expression to display in a text input.  The regex is defined as:







      private var myRegExp:RegExp=/^.*(?=.{10,32})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[.!@#$%*^&()+]).*$/;


      In my form, I want to display the actual expression.  The code I am using to do so is:







      <mx:FormItem label="regExpLabel">



           <mx:TextInput id="regExpTextInput" text="{myRegExp}" />





      When I run the app, the data displayed in the regExpTextInput filed is /^.*(?=.{10,32})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[.!@#$%*^&()+]).*$/


      What I want to display is only the regular expression, not including the slashes required by Flex at the beginning and end of the string.  The data I want displayed is ^.*(?=.{10,32})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[.!@#$%*^&()+]).*$


      I tried changing my variable type to String and leaving out the beginning and ending slashes, but that did not work either.  Any thoughts?



        • 1. Re: How to display regular expression text
          ShardulSingh Level 3

          Hi, I am unable to understand your requirement properly but here is one demo of the using regular expression. In this application I am allowing only those character to be enter in the Textbox which are taken as the valid filename. Hope this will help you.

          I think In your requirement first of all you have to take it as string type. And the second is that use \\ before every special character if you are writing it in the script. As I have done. Pls let me know if you

          Have any issue with the code below.



          <?xml version="1.0" encoding="utf-8"?>

          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">





                private var regExpForFile : String

                = "0-9A-Za-z\\&\\`\\~\\!\\@\\#\\$\\%\\^\\(\\)\\-\\_\\=\\+\\]\\}\[\\'\\;\\,\\.\\{ ";




                <mx:VBox horizontalAlign="center" width="350">

                      <mx:Label text="Enter File Name"/>

                      <mx:TextInput id="fileName" width="170" height="20"  restrict="{regExpForFile}"/>








          with Regards,

          Shardul Singh Bartwal



          • 2. Re: How to display regular expression text
            Barna Biro Level 3

            Use to "source" property to display the regexp source:


                import flash.display.Sprite;
                public class RegExpTest extends Sprite
                    private var _regExp:RegExp = /^.*(?=.{10,32})(?=.*\d).*$/;
                    public function RegExpTest()
                        trace(_regExp.source); // displays: ^.*(?=.{10,32})(?=.*\d).*$


            I don't think it gets more simple than that. Good luck.

            • 3. Re: How to display regular expression text
              lee704 Level 1

              Thanks Shardul.  I did not ask the question properly, but your explination helped.  I needed to escape the \ in my expression.  So, instead of having an expression of:




              I have an expression of:




              This corrected my issue.  Thanks again!




              • 4. Re: How to display regular expression text
                lee704 Level 1

                Is Sprite only available in Flex SDK 4?