Pulling info with Regular Expression...

Discussion in 'HTML' started by scole954387@gmail.com, May 27, 2006.

  1. Guest

    , May 27, 2006
    #1
    1. Advertising

  2. BootNic Guest

    > "" <> wrote:
    > news:....
    >
    > Can someone help me pull information from this URL using regular
    > expression?
    >
    > http://www.amazon.com/exec/obidos/tg/browse/-/15324461/ref=br_bx_c_1_129/103-6750759-7559044
    >
    > I want to pull the 15324461 from the url.
    >

    <script type="text/javascript">
    var url='http://www.amazon.com/exec/obidos/tg/browse/'+
    '-/15324461/ref=br_bx_c_1_129/103-6750759-7559044';
    alert(url.match(/\d+/))
    </script>

    --
    BootNic Saturday, May 27, 2006 6:58 PM

    When I was younger, I could remember anything, whether it had
    happened or not.
    *Mark Twain*
     
    BootNic, May 27, 2006
    #2
    1. Advertising

  3. Guest

    Thanks for the reply.

    Actually, this is what I have:

    <a
    href=/exec/obidos/tg/browse/-/########/ref=br_bx_c_1_2/104-1330076-7765538>Various
    Text</a>

    Using a regular expression (for use with preg_match in PHP), how can I
    just pull out the numbers (##########)?

    Thanks,

    S. Cole
     
    , May 28, 2006
    #3
  4. Guest

    I found a workaround that worked just as well. For anyone
    interested...

    I took the url and exploded it by the "/".

    This created an array with each portion between the /s. All I had to
    do to access the numbers I wanted was to reference that part of the
    array.

    For example to access the "#########" I just had to reference
    $array[6].

    S. Cole
     
    , May 28, 2006
    #4
  5. Toby Inkster Guest

    scole954387 wrote:

    > http://www.amazon.com/exec/obidos/tg/browse/-/15324461/ref=br_bx_c_1_129/103-6750759-7559044


    You don't mention which programming language -- there are tonnes out there
    that each support their own idea of regular expressions.

    Using Perl:

    #!/usr/bin/perl
    $url = 'http://www.amazon.com/exec/obidos/tg/browse/-/15324461/ref=br_bx_c_1_129/103-6750759-7559044';
    @parts = split(/\//, $url);
    $number = $parts[8];
    print $number;

    Or in PHP, you probably don't even need regular expressions:

    <?php
    $url = 'http://www.amazon.com/exec/obidos/tg/browse/-/15324461/ref=br_bx_c_1_129/103-6750759-7559044';
    $parts = explode('/', $url);
    $number = $parts[8];
    print $number;
    ?>

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
    Now Playing ~ ./lighthouse_family/high.ogg
     
    Toby Inkster, May 28, 2006
    #5
  6. BootNic Guest

    > "" <> wrote:
    > news:....
    >
    > Thanks for the reply.
    >
    > Actually, this is what I have:
    >
    > <a
    > href=/exec/obidos/tg/browse/-/########/ref=br_bx_c_1_2/104-1330076-7765538>Various
    > Text</a>
    >
    > Using a regular expression (for use with preg_match in PHP), how
    > can I just pull out the numbers (##########)?


    <?php
    $mystring="<a href='http://www.amazon.com/exec/obidos/tg/browse/-/15324461/ref=br_bx_c_1_129/103-6750759-7559044'>some text</a>";
    $reg="/\d+/";
    preg_match($reg, $mystring, $matches);
    print "Numbers are : {$matches[0]}";
    ?>

    --
    BootNic Sunday, May 28, 2006 2:41 PM

    Have no fear of perfection - you'll never reach it.
    *Salvador Dali*
     
    BootNic, May 28, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VSK
    Replies:
    2
    Views:
    2,397
  2. Replies:
    3
    Views:
    548
    Wibble
    May 28, 2005
  3. =?iso-8859-1?B?bW9vcJk=?=

    Matching abitrary expression in a regular expression

    =?iso-8859-1?B?bW9vcJk=?=, Dec 1, 2005, in forum: Java
    Replies:
    8
    Views:
    886
    Alan Moore
    Dec 2, 2005
  4. bob

    pulling info from website

    bob, Jan 10, 2005, in forum: Python
    Replies:
    3
    Views:
    394
    Jorgen Grahn
    Jan 12, 2005
  5. Replies:
    20
    Views:
    758
Loading...

Share This Page