rlb1
asked on
How do I eliminate a result in Regex?
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.
Here is the original code and the results I want:
Here are the results I DONT want:
Thanks for your help!!
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);
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
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>
Thanks for your help!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
lol... I was a few secs too slow :-)
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." = )
Only just got the alert in my inbox.... I need a faster mail server!
ASKER
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!
Have a good one!
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.
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);