www.webdeveloper.com
Results 1 to 3 of 3

Thread: trying to do is to match and catch the END characters

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Posts
    192

    trying to do is to match and catch the END characters

    var str = "xxx.abc.xyz.gif";
    var patt = /\..+$/i;
    var result = patt.exec(str);

    What I am trying to do is to match and catch the END characters after the last ".", such as "gif".

    Example:
    var str = "aaaa.bbbb.cccc.tiff";

    I want to match and catch the "tiff" only so that the result will return "tiff".

    How should I write the pattern expression?

  2. #2
    Join Date
    Nov 2002
    Location
    Flint, Michigan, USA
    Posts
    588
    Are you required to use a regular expression? If not:
    Code:
    var str = "aaaa.bbbb.cccc.tiff";
    var Rtn=str.substring(str.lastIndexOf('.')+1);

  3. #3
    Join Date
    Jun 2008
    Posts
    106
    jalarie's code works, but if you truly want (or need) a regular expression, this is simple but gets the job done:

    Code:
    var str = "aaaa.bbbb.cccc.tiff",
        result = str.match(/\.(\w+)$/)[1];
    In the meantime, you should probably read more about regular expressions. And if you don't need one, don't use one unless it makes things severely less complicated.

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