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

x
?
Solved

How do I eliminate a result in Regex?

Posted on 2011-09-29
7
Medium Priority
?
297 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
[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
7 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 1000 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 1000 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
Industry Leaders: 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 111

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

Industry Leaders: 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!

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
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.

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