#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2005
    Posts
    52
    Rep Power
    9

    Match and Catch string xxx.abc.xyz.gif


    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
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,066
    Rep Power
    9398
    When you say "end characters after the last ." you're implying that none of those characters are themselves periods. Try expressing that in the regex too.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    832
    Rep Power
    496
    Maybe this:
    Code:
    /\.(\w+)$/
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2005
    Posts
    52
    Rep Power
    9
    Many thanks.

IMN logo majestic logo threadwatch logo seochat tools logo