Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 421267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:57:59+00:00 2026-05-12T18:57:59+00:00

here is a regex i got from: a blog i can’t link to because

  • 0

here is a regex i got from: a blog i can’t link to because i am new… just google amazon short url and click on the blog post by noah coad

as you can see from this page… it is supposed to extract the unique product id from any amazon url so you can shorten it… or use it to pull info from amazon apis.

here is the sample code i am trying to use to get it to work:

<?php
$example_url = 'http://www.amazon.com/dp/1430219483/?tag=codinghorror-20';    

$reg = '(?:http://(?:www\.){0,1}amazon\.com(?:/.*){0,1}(?:/dp/|/gp/product/))(.*?)(?:/.*|$)';

echo 'test<br/>';

echo preg_match($reg,$example_url);
?>

and here is my output:

test

Warning: preg_match() [function.preg-match]: Unknown modifier '(' in /Users/apple/Sites/amazon/asin_extract.php on line 14

thanks so much! this is my first time posting on this site where i have found countless answers already

on second hand… take back some of my thanks for this painful first time submission process… i had to trim this question since it thinks my regex patterns are urls

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T18:57:59+00:00Added an answer on May 12, 2026 at 6:57 pm

    Your regex probably needs delimiters : a character that will be present at the beginning and the end of it.

    This comment on the PHP manual is interested, about this 🙂

    ‘/‘ is often used ; but some people prefer ‘#‘ — the second one being nice for URLs

    So :

    $reg = '#(?:http://(?:www\.){0,1}amazon\.com(?:/.*){0,1}(?:/dp/|/gp/product/))(.*?)(?:/.*|$)#';
    

    And, with the full code, a bit modified to capture the results :

    $example_url = 'http://www.amazon.com/Professional-Visual-Studio-System-Programmer/dp/0764584367/ref=sr_1_1/104-4732806-7470339?ie=UTF8&s=books&qid=1179873697&sr=8-1';
    $reg = '#(?:http://(?:www\.){0,1}amazon\.com(?:/.*){0,1}(?:/dp/|/gp/product/))(.*?)(?:/.*|$)#';
    echo 'test<br/>';
    
    $matches = array();
    echo preg_match($reg,$example_url, $matches);
    
    var_dump($matches);
    

    The output you get from the var_dump is :

    array
      0 => string 'http://www.amazon.com/Professional-Visual-Studio-System-Programmer/dp/0764584367/ref=sr_1_1/104-4732806-7470339?ie=UTF8&s=books&qid=1179873697&sr=8-1' (length=149)
      1 => string '0764584367' (length=10)
    

    And $matches[1] is 0764584367.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I’m trying to validate input by using egrep and regex.Here is the line from
Here's my regex code: preg_match_all('/background[-image]*:[\s]*url\([|\']+(.*)[|\']+\)/', $css, $matches, PREG_SET_ORDER); It looks for CSS that looks
I want to route url through Zend route regex with Swedish character and here
I am a regex newbie and can't seem to figure this one out. Here
I got this RegEx from another post, but it doesn't fully function like it
Here's a regex for validating emails - \S+@\S+\.\S+ , I didn't write it. I'm
In need of a regex master here! <img src=\img.gif style=float:left; border:0 /> <img src=\img.gif
Here's a basic regex technique that I've never managed to remember. Let's say I'm
I've managed to find the Regex to get almost the result I want here
How to find below comment block(s) with javascript/jquery regex: /* some description here */

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.