Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

What is the best way to Regex this?

Posted on 2015-01-18
4
Medium Priority
?
78 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
  • 2
4 Comments
 
LVL 85

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 1400 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 85

Assisted Solution

by:ozo
ozo earned 600 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to create an extensible mechanism for linked drop downs.
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 count occurrences of each item in an array.
Suggested Courses

971 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