Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I eliminate a result in Regex?

Posted on 2011-09-29
7
Medium Priority
?
299 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 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

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…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

916 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