Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need assistance with REGEX statement

Posted on 2015-01-17
6
Medium Priority
?
75 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
[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
  • 2
  • 2
6 Comments
 
LVL 84

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 84

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
Technology Partners: 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 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to implement server side field validation and display customized error messages to the client.
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 …

715 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