Solved

How do I eliminate a result in Regex?

Posted on 2011-09-29
7
294 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 75

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
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 75

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 110

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses four methods for overlaying images in a container on a web page
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.

679 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