SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Get dimensions from text

    I have a string that looks similar to this:
    Code:
    tumblr_mgn6mfe9aD1rbaz5bo1_500.jpg (500705)
    I want to strip the text until I get the value 500 & 705. I want them as two separate values. How can I do this in javascript?

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,890
    Mentioned
    211 Post(s)
    Tagged
    12 Thread(s)
    Hi there,

    The following reg-ex matches a bracket, at least one number, an 'x', at least one number and a closing bracket.

    Code JavaScript:
    var str="tumblr_mgn6mfe9aD1rbaz5bo1_500.jpg (500x705)"; 
    var match=str.match(/\((\d+)x(\d+)\)/);
    console.log(match[1]);
    console.log(match[2]);

    Outputs:
    500
    705

    HTH

  3. #3
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I forgot to say that the is an ascii character and it's not the regular 'x' so your code doesn't work with the ASCII ''

  4. #4
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,890
    Mentioned
    211 Post(s)
    Tagged
    12 Thread(s)
    Hey,

    Just replace the x with . (i.e. a single dot)


Bookmarks

Posting Permissions

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