?
Solved

How do you correctly structure an "|" either/or REGEX statement

Posted on 2011-04-28
8
Medium Priority
?
338 Views
Last Modified: 2012-05-11
Experts,
I know the way I am doing this is a little elementary, but I am trying to learn...  (Please keep the response fairly simple. I do not quite understand the complex Regex yet...)

How do I correctly structure this REGEX statement.  I have the brackets "|" in place to make this be an either/or statement and my other similar statement works fine.

I am getting a weird error that I cannot figure out, so I am thinking it means something is wrong above the end line...

Parse error: syntax error, unexpected ',' in /home/public_html/feed.php on line 175

(I am making a product feed for my store to submit to Shopping.com, Google Base, etc.  All of my other REGEX statements work fine with   %statement_here%s',$buf1,$matches80);

Thanks for your help!!
preg_match('%<td align="right">Availability:<\/td>
                        <td  style="font-weight:bold;">
                            <font class="greensmbold"> (.*?) <\/font><font class="greensmbold">(.*?) <span class="blacksmbold">(.*?) <a class="blacksmbold" style="text-decoration:underline;" href="/shipping_tips.asp?" target="_blank" onclick="javascript:popup\('/shipping_tips.asp?'\); return false;">(.*?)<\/a><\/span><\/font>
                        <\/td>
                   <\/tr>|<td align="right">Availability:<\/td>
                        <td  style="font-weight:bold;">
                            <font class="blacksmbold">(.*?)<\/font>
                        <\/td>|<td align="right">Availability:<\/td>
                        <td  style="font-weight:bold;">
                            <font class="redsmbold">(.*?)<\/font><font class="blacksmbold">(.*?)<\/font>
                        <\/td>%s',$buf4,$matches85);
$a=$matches85[1];
$b=$matches85[2];
$c=$matches85[3];
$d=$matches85[4];



$stockmessage = $a . $b . $c . $d;

echo $stockmessage."<br />";

Open in new window

0
Comment
Question by:rlb1
  • 3
  • 3
  • 2
8 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 35486408
Let's start with the basics.  Parse error: syntax error, unexpected ',' in /home/public_html/feed.php on line 175

Please show us line 175 and the lines leading up to it.  There are only 21 lines in the script you posted!
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 35486437
Also, now that I try to read that slug of code, it might be easier to do what ever you are trying if you step back from the technical details and give us two pieces of information.

1. Give us an example of the input data.
2. Give us an example of what you're trying to get as a result, after processing the input data.

Thanks, ~Ray
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 1400 total points
ID: 35486614
There's no reason to escape the forward slashes for your closing tags since you changed the pattern delimiter to %. Also, you have some unescaped single quotes in the part that attempts to match the javascript code.
onclick="javascript:popup\('/shipping_tips.asp?'\)

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35486638
Note:  those are PHP-related escapes, not regex  : )
0
 

Author Comment

by:rlb1
ID: 35486971
Thank you Kaufmed!


Ray,
From here on out, please do not respond to my questions.  Every question that you resond to of mine reflects your "holier than thou" attitude!  I have had enough of it!  There are a lot of people such as Kaufmed who have taken a geniune interest in trying to help me instead of insulting me with "slug of code", etc.

If I was a PHP god, and CEO of a huge company like you, I would not be asking questions!   I am still trying to learn - at my pace!  

Sincerely,

Randy
0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 600 total points
ID: 35488834
Randy: "Slug" is not a pejorative - it is a term of art.  Please do not be offended by it, any more than you would be offended by "block" or "segment."  Instead, let's try to work together:

1. Give us an example of the input data.
2. Give us an example of what you're trying to get as a result, after processing the input data.

Armed with that information we can give you a good answer.

EE does not give us a way to filter out questions by the author name or the expert name.  I have asked for this feature in the past and I have been told it will not be made available.  Sorry - that is just the way it is.
0
 

Author Comment

by:rlb1
ID: 35492993
Got it to work after about 3 hours of working on it and trying different things.  Thanks!
0
 

Author Closing Comment

by:rlb1
ID: 35493002
Thanks!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
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 look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

840 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