Solved

What is the best way to Regex this?

Posted on 2015-01-18
4
75 Views
Last Modified: 2015-01-18
I need to Regex this statement:  What is the easiest way to accomplish?

Pro Audio > Audio Recording > Drum Machines/Samplers > Alesis SR18 Portable High-Definition

I need:
Pro Audio
Audio Recording
Drum Machines/Samplers

<span class="head2"><strong><a href="category/pro-audio/1"><span class="head2">Pro Audio</span></a> </strong></span><strong> <span class="head3">&gt;</span> <a href="category/pro-audio/audio-recording/1">Audio Recording</a>

Open in new window



My attempt which did not work...
<span class="head2"><strong><a href="category\/.*?\/1"><span class="head2">(.*?)<\/span><\/a><\/strong><\/span><strong>\s<span class="head3">&gt;<\/span>\s<a href="category\/.*?\/.*?\/1">(.*?)<\/a>\s+\&gt;\s<a href="products\/.*?\/.*?\/.*?/1">(.*?)<\/a> <\/span>\s+\&gt;\s(.*?)\s+<\/span>\s+<\/strong>\s+<\/td>

Open in new window



preg_match('%<span class="head2"><strong><a href="category\/.*?\/1"><span class="head2">(.*?)<\/span><\/a><\/strong><\/span><strong>\s<span class="head3">&gt;<\/span>\s<a href="category\/.*?\/.*?\/1">(.*?)<\/a>\s+\&gt;\s<a href="products\/.*?\/.*?\/.*?/1">(.*?)<\/a> <\/span>\s+\&gt;\s(.*?)\s+<\/span>\s+<\/strong>\s+<\/td>%si',$buffer4,$matches4);

$a=$matches4[1];
$b=$matches4[2];
$c=$matches4[3];
$d=$matches4[4];


echo "a:&nbsp;&nbsp;".$a."<BR>";
echo "b:&nbsp;&nbsp;".$b."<BR>";
echo "c:&nbsp;&nbsp;".$c."<BR>";
echo "d:&nbsp;&nbsp;".$d."<BR>";

Open in new window

0
Comment
Question by:lawrence_dev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 40556943
<\/a><\/strong>
should be
<\/a>\s*<\/strong>
or
</a>\s+</strong>

I also don't see the part of
<span class="head2"><strong><a href="category/pro-audio/1"><span class="head2">Pro Audio</span></a> </strong></span><strong> <span class="head3">&gt;</span> <a href="category/pro-audio/audio-recording/1">Audio Recording</a>
that's supposed to match \&gt;\s<a href="products
0
 
LVL 46

Accepted Solution

by:
aikimark earned 350 total points
ID: 40556962
Try this:
<span class="head2"><strong><a href="category/.*?/1"><span class="head2">(.*?)</span></a>\s*</strong></span><strong>\s<span class="head3">&gt;</span>\s<a href="category/.*?/.*?/1">(.*?)</a>(?:\s+\&gt;\s<a href="products/.*?/.*?/.*?/1">(.*?)</a> </span>\s+\&gt;\s(.*?)\s+</span>\s+</strong>\s+</td>)?

Open in new window

0
 

Author Comment

by:lawrence_dev
ID: 40556986
Thanks Aikimark!!  I am half way there.  I played with it a little and could not make it work.

Notice: Undefined offset: 3 on line 281

Notice: Undefined offset: 4  on line 282
a:  Pro Audio
b:  Live Sound
c:  
d:
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 150 total points
ID: 40556990
What was in the original string that should have matched offset: 3 and offset:4?
There was nothing in
http://www.experts-exchange.com/viewCodeSnippet.jsp?refID=28599127&rtid=10&icsi=1
that would have produced anything for c: and d:
0

Featured Post

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question