Solved

How do I eliminate a result in Regex?

Posted on 2011-09-29
7
296 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 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses four methods for overlaying images in a container on a web page
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…
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…

623 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