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

x
?
Solved

Need assistance with REGEX statement

Posted on 2015-01-17
6
Medium Priority
?
77 Views
Last Modified: 2015-01-18
How do I grab just "AIRFONIX AFX-19AR050" from this statement?  (I have multiple statements structured the same way)  Basically, I need everything before the Upper and Lower Case text starts 'Active 50W Mono/25+25W Stereo'.  

AIRFONIX AFX-19AR050 Active 50W Mono/25+25W Stereo

(Brand and Stock Number followed by description)
0
Comment
Question by:lawrence_dev
  • 2
  • 2
  • 2
6 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 40555742
print "AIRFONIX AFX-19AR050 Active 50W Mono/25+25W Stereo" =~ /^([^a-z]*)\b/
0
 

Author Comment

by:lawrence_dev
ID: 40555785
THANKS!!   How do I preg match an existing variable with your regex:   ($title is the existing variable)

preg_match('%^([^a-z]*)\b%',$title,$matches51);

$BrandMPN=$matches51[1];

echo "BrandMPN:&nbsp;&nbsp;".$BrandMPN."<BR>";

Open in new window

0
 
LVL 85

Accepted Solution

by:
ozo earned 2000 total points
ID: 40555800
#!/bin/php
<?php
$title="AIRFONIX AFX-19AR050 Active 50W Mono/25+25W Stereo";

preg_match('%^([^a-z]*)\b%',$title,$matches51);

$BrandMPN=$matches51[1];

echo "BrandMPN:&nbsp;&nbsp;".$BrandMPN."<BR>";
?>
0
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.

 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40556087
From the look of this and your other recent questions it appears that you're trying to scrape product information from an eCommerce web site.  There are many well-understood design patterns that can help.  If you want to show us a link to the page you're trying to scrape, or at least a few samples of the "multiple statements structured the same way" E-E may be able to help you make very rapid progress toward your goal.
0
 

Author Closing Comment

by:lawrence_dev
ID: 40556686
Worked great!  Thanks for the help!
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40557080
For anyone coming upon this question in the future, please be aware that the regular expression used as a solution here says, in essence, "match the absence of the lower-case characters up to the first word boundary."  One good learning resource for regular expressions is available here:
http://www.regular-expressions.info/tutorial.html
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

972 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