Solved

What is the best way to Regex this?

Posted on 2015-01-18
4
74 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 45

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

738 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