Solved

How do I eliminate a result in Regex?

Posted on 2011-09-29
7
290 Views
Last Modified: 2012-06-27
Experts:

How do I eliminate any result that starts with http in this preg match script?  Please advise how to structure or modify my REGEX statement to ignore http, or a URL.

//value="([^"]*)"   Allow eveything except for URL or http here.

preg_match_all('#<option value="([^"]*)"\s*(?:selected)?>([a-zA-Z]{1,10})#i',$buffer,$matches39); 

Open in new window


Here is the original code and the results I want:

// WANT :   BSC1.5XXJ    Black


<option value="BSC1.5XXJ" selected>Black

<option value="BSC1.5XXJBE" >Blue

<option value="BSC1.5XXJRD" >Red

<option value="BSC1.5XXJGN" >Green

<option value="BSC1.5XXJYW" >Yellow

<option value="BSC1.5XXJGY" >Gray

Open in new window



Here are the results I DONT want:

//DO NOT WANT :  http://www.website.com/ProdList.asp?mfg=West+Penn+Wire+Corp



<option value="http://www.website.com/ProdList.asp?mfg=West+Penn+Wire+Corp">West Penn Wire C</option>
 
<option value="http://www.website.com/ProdList.asp?mfg=Wharfedale+Pro">Wharfedale Pro</option>

Open in new window



Thanks for your help!!
0
Comment
Question by:rlb1
7 Comments
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
ID: 36818063
Try this:

preg_match_all('#<option value="(?!http)([^"]*)"\s*(?:selected)?>([a-zA-Z]{1,10})#i',$buffer,$matches39);

Open in new window

0
 
LVL 35

Assisted Solution

by:Terry Woods
Terry Woods earned 250 total points
ID: 36818065
Try this:

preg_match_all('#<option value="(?!https?://)([^"]*)"\s*(?:selected)?>([a-zA-Z]{1,10})#i',$buffer,$matches39);
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 36818068
lol... I was a few secs too slow :-)
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 36818077
Heheh...  What's really funny is that when I saw the question I said to myself, "I wonder why Terry hasn't answered this already! Maybe he's still asleep."   = )
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 36818087
Only just got the alert in my inbox.... I need a faster mail server!
0
 

Author Closing Comment

by:rlb1
ID: 36818301
Thanks again!  If you think the other deserves all of the points... thats your business and you can fight amongst yourselves LOL!  Taking there of those who go a long way to help me...  Thats my business!!!  

Have a good one!
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 36818358
http://www.laprbass.com/RAY_temp_rlb1.php
Use "view source" to see the work product in clear text.  It looks to me like the easiest way is not necessarily the regex way based on the examples of the test data you posted.  However if the test data you posted is not really representative of all the input the algorithm might expect and you want to post a new set of test data I will be glad to look at that, too.
<?php // RAY_temp_rlb1.php
error_reporting(E_ALL);

// TEST DATA FROM THE POST AT EE
$str = <<<STR
<option value="BSC1.5XXJ" selected>Black
<option value="BSC1.5XXJBE" >Blue
<option value="BSC1.5XXJRD" >Red
<option value="BSC1.5XXJGN" >Green
<option value="BSC1.5XXJYW" >Yellow
<option value="BSC1.5XXJGY" >Gray
<option value="http://www.website.com/ProdList.asp?mfg=West+Penn+Wire+Corp">West Penn Wire C</option>
<option value="http://www.website.com/ProdList.asp?mfg=Wharfedale+Pro">Wharfedale Pro</option>
STR;

// LOAD AN ARRAY
$arr = explode(PHP_EOL, $str);

// USE AN ITERATOR TO EXAMINE THE ARRAY
foreach ($arr as $key => $txt)
{
    // REMOVE THE ELEMENTS WITH HTTP
    if (stripos($txt, 'http://')) unset($arr[$key]);
}

$new = implode(PHP_EOL, $arr);

// SHOW THE ORIGINAL AND THE RESULTS
var_dump($str);
var_dump($new);

Open in new window

0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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 count occurrences of each item in an array.

708 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

14 Experts available now in Live!

Get 1:1 Help Now