We help IT Professionals succeed at work.
Get Started

How do I fix this REGEX statement

rlb1 asked
Last Modified: 2012-05-10

How do I fix this regex statement and pull out the desired data?

I am trying to ignore the cat_id        cat_id=([.*])     using the "  .* "  tag,  and only pull out the category name located where the   (.*?)  

Original String:
<a href="/categories.asp?cat_id=([.*])">(.*?)</a>

Original Result:
Audio Video Cables > Video Cables > HDMI Cables

Thanks for your help!!
//Original Code

<div id="product_header">
<a href="/categories.asp?cat_id=2000">Audio Video Cables</a> &gt; <a href="/categories.asp?cat_id=8820003">Video Cables</a> &gt; <a href="/categories.asp?cat_id=2030">HDMI Cables</a>

My Attempt:
// Categories
preg_match_all('%<div id="product_header">
        <a href="/categories.asp?cat_id=([.*])">(.*?)</a> &gt; <a href="/categories.asp?cat_id=([.*])">(.*?)</a> &gt; <a href="/categories.asp?cat_id=([.*])">(.*?)</a>


echo $category."<br />";
echo $subcat."<br />";
echo $subsubcat."<br />";

Open in new window

Watch Question
Web Application Programmer
This problem has been solved!
Unlock 4 Answers and 10 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE