Solved

Need assistance with REGEX statement

Posted on 2015-01-17
6
64 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 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 500 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 108

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 108

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now