Pulling info with Regular Expression...

B

BootNic

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*
 
S

scole954387

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
 
S

scole954387

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
 
T

Toby Inkster

scole954387 said:

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;
?>
 
B

BootNic

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]}";
?>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top