www.webdeveloper.com
Results 1 to 3 of 3

Thread: Problem with Regular Expressions

  1. #1
    Join Date
    Dec 2009
    Posts
    15

    Question Problem with Regular Expressions

    I'm trying to determine if the id of an element matches a String that has multiple parts.

    Code:
    function platformChange (this)
    {
       thisID = this.id;
    
       var pattern = "SWFUpload_\d_\d";
       var match = thisID.match (pattern);
    ...
    }
    The value of this.id is "platform_SWFUpload_0_0" but the result of thisID.match (pattern) is null.

    Can someone please explain what I'm doing wrong and how I can make this work?

    Thanks.

  2. #2
    Join Date
    Oct 2008
    Location
    U.S.
    Posts
    726
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
    <title>Some Title</title>
    <script type="text/javascript">
    function platformChange(el){
        thisID = el.id;
         //I'm assuming that you may have wanted to pull the numbers out of the id also:
        var pattern = /^SWFUpload_(\d+)_(\d+)$/;
        var match = thisID.match(pattern);
        var arr = (match !== null) ? match : ['match', 'was', 'null'];
        alert(arr.join('\n'));
    }
    </script>
    </head>
    <body>
    <div>
    <button type="button" id="SWFUpload_10_0" onclick="platformChange(this);">Click Me</button>
    </div>
    </body>
    </html>

  3. #3
    Join Date
    Dec 2009
    Posts
    15

    Thumbs up

    Quote Originally Posted by astupidname View Post
    Code:
         //I'm assuming that you may have wanted to pull the numbers out of the id also:
    Actually, I'm just trying to match the pattern of SWFUpload_#_# but this gives me something to work with.

    Thanks for the quick reply.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles