phpuser2013 Posted May 15, 2013 Share Posted May 15, 2013 Hi,I would like to have one expression://1. expression$regex = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/'; //verify email//2. expressionpreg_match_all('~<(td)>(?<content>\w+)</\1>~Uis', $gesamteDatei, $result, PREG_SET_ORDER); //get values of the data set, which are// the 2. expression doesnt match any email adressI tried it, but I failed and I dont know why... may be you can help me ?preg_match_all('~<(td)>(?<content>/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/)</\1>~Uis', $gesamteDatei, $result, PREG_SET_ORDER);Thanks for your help (: Quote Link to comment https://forums.phpfreaks.com/topic/278035-make-of-2-regular-expressions-1-regular-expression/ Share on other sites More sharing options...
requinix Posted May 15, 2013 Share Posted May 15, 2013 Those two are not compatible: the second requires the "content" be only letters, numbers, and underscores while email addresses need @s. Quote Link to comment https://forums.phpfreaks.com/topic/278035-make-of-2-regular-expressions-1-regular-expression/#findComment-1430252 Share on other sites More sharing options...
phpuser2013 Posted May 15, 2013 Author Share Posted May 15, 2013 what can I do ? Quote Link to comment https://forums.phpfreaks.com/topic/278035-make-of-2-regular-expressions-1-regular-expression/#findComment-1430258 Share on other sites More sharing options...
Irate Posted May 15, 2013 Share Posted May 15, 2013 Why would you even need to have 2 regexps for that? You can test for two conditions with an if statement... Quote Link to comment https://forums.phpfreaks.com/topic/278035-make-of-2-regular-expressions-1-regular-expression/#findComment-1430260 Share on other sites More sharing options...
ignace Posted May 15, 2013 Share Posted May 15, 2013 (edited) I guess this does what you want? // match <td>some@email.com</td> if (preg_match_all('~<(td)>(?<content>[_a-z0-9-]+(?:\.[_a-z0-9-]+)*@[a-z0-9-]+(?:\.[a-z0-9-]+)*(?:\.[a-z]{2,3}))</\1>~Uis', $gesamteDatei, $matches)) { foreach ($matches['content'] as $email) { // } }If you want to test your regular expressions, you can do so here: http://www.solmetra.com/scripts/regex/index.php Edited May 15, 2013 by ignace Quote Link to comment https://forums.phpfreaks.com/topic/278035-make-of-2-regular-expressions-1-regular-expression/#findComment-1430268 Share on other sites More sharing options...
phpuser2013 Posted May 15, 2013 Author Share Posted May 15, 2013 (edited) Thanks for your help so far,I got a file where i want...<tr><td>value 1</td><td>value 1</td><td>value 2</td><td>value 3</td><td>value 4</td><td>value 5</td><td>value 6</td><td>email</td><td>value 8</td></tr> ... //1 datasetThe problem is that the value is mostly at a different position:like ->...<tr><td>value 1</td><td>value 1</td><td>value 2</td><td>value 3</td><td>value 4</td><td>email</td><td>value 6</td><td>value 7</td><td>value 8</td></tr> ... //1 datasetor like ->...<tr><td>value 1</td><td>value 1</td><td>value 2</td><td>value 3</td><td>value 4</td><td>value 5</td><td>value 6</td><td>value 7</td><td>email</td></tr> ... //1 datasetand I need some of the value left or right of that field,I tried to solve it like this: preg_match_all('/<td>(.*?)<\/td>/',$gesamteDatei,$InhaltTdElemente); //find values$gesamteDatei= whole stream(1 table and many datasets)$InhaltTdElemente= all values between <td> </td>I need to search for something"(ZiP, Country....)preg_match_all('~<(td)>(?<content>\w+)</\1>~Uis', $gesamteDatei, $result, PREG_SET_ORDER);// that doesnt give me the email address <?php print "<html>"; print "<head>"; print "</head>"; print "<body>"; print "<nobr>"; $datei='new_folders42000.html'; // stream $pfad='/xampp/htdocs/xampp/new/'; //path to stream if($gesamteDatei=file_get_contents($datei)){ //checking access printf(" <div style='background:lime'>Datei kann ausgelesen werden !</div><br>\n"); //reading ok preg_match_all('/<td>(.*?)<\/td>/',$gesamteDatei,$InhaltTdElemente); //whole content preg_match_all('~<(td)>(?<content>\w+)</\1>~Uis', $gesamteDatei, $result, PREG_SET_ORDER); // /*checking email */ $lange=count($InhaltTdElemente[1]); for($i=0;$i<$lange;$i++){ $email = $InhaltTdElemente[1][$i]; // alle Felder $regex = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/'; if (preg_match($regex, $email)) { echo $email.'<br/>'; } else { //echo $email ." is an invalid email. Please try again."; } } echo '<br/>'; echo '<br/>'; $country_code="DE"; //regular expression germany //Checking zip_clode $ZIPREG=array( "US"=>"^\d{5}([\-]?\d{4})?$", "UK"=>"^(GIR|[A-Z]\d[A-Z\d]??|[A-Z]{2}\d[A-Z\d]??)[ ]??(\d[A-Z]{2})$", "DE"=>"\b(?!01000)(?!99999)(0[1-9]\d{3}|[1-9]\d{4})\b", "CA"=>"^([ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ])\ {0,1}(\d[ABCEGHJKLMNPRSTVWXYZ]\d)$", "FR"=>"^(F-)?((2[A|B])|[0-9]{2})[0-9]{3}$", "IT"=>"^(V-|I-)?[0-9]{5}$", "AU"=>"^(0[289][0-9]{2})|([1345689][0-9]{3})|(2[0-8][0-9]{2})|(290[0-9])|(291[0-4])|(7[0-4][0-9]{2})|(7[8-9][0-9]{2})$", "NL"=>"^[1-9][0-9]{3}\s?([a-zA-Z]{2})?$", "ES"=>"^([1-9]{2}|[0-9][1-9]|[1-9][0-9])[0-9]{3}$", "DK"=>"^([D-d][K-k])?( |-)?[1-9]{1}[0-9]{3}$", "SE"=>"^(s-|S-){0,1}[0-9]{3}\s?[0-9]{2}$", "BE"=>"^[1-9]{1}[0-9]{3}$" ); for($i=0,$max = count($result); $i < $max; $i++) { $zip_postal=$result[$i]['content']; if ($ZIPREG[$country_code]) { //at the moment germany if (!preg_match("/".$ZIPREG[$country_code]."/i",$zip_postal)){ //check german zip //Validation failed, provided zip/postal code is not valid. } else { //Validation passed, provided zip/postal code is valid. if($result[$i]['content'] >=50000 && $result[$i]['content'] <= 60000) { //range of zip //$datei=fopen($pfad.'56000.html','w+'); //trying to read fields printf($result[$i]['content'].'<br/>'); printf($result[$i-1]['content'].'<br/>'); printf($result[$i-2]['content'].'<br/>'); printf($result[$i-3]['content'].'<br/>'); printf($result[$i-4]['content'].'<br/>'); printf($result[$i-5]['content'].'<br/>'); printf($result[$i-6]['content'].'<br/>'); printf($result[$i-7]['content'].'<br/>'); printf($result[$i-8]['content'].'<br/>'); printf($result[$i-9]['content'].'<br/>'); printf($result[$i+1]['content'].'<br/>'); printf($result[$i+2]['content'].'<br/>'); printf($result[$i+3]['content'].'<br/>'); printf($result[$i+4]['content'].'<br/>'); printf('<br>'); //fclose($datei); } } } else { //Validation not available } } // if ( preg_match('/^\d{5}$/', $input) && (int) $input > 1000 && (int) $input < 99999 ) {} //fclose($datei); } } }else{ printf(" <div style='background:red'>Datei kann nicht ausgelesen werden !</div><br>\n"); } print "</nobr>"; print "</body>"; print "</html>"; ?> Edited May 15, 2013 by phpuser2013 Quote Link to comment https://forums.phpfreaks.com/topic/278035-make-of-2-regular-expressions-1-regular-expression/#findComment-1430285 Share on other sites More sharing options...
jazzman1 Posted May 15, 2013 Share Posted May 15, 2013 What did you expect from us to read all bunch of code? Turn on error_reporting and tell us what part of the script you don't understand. Quote Link to comment https://forums.phpfreaks.com/topic/278035-make-of-2-regular-expressions-1-regular-expression/#findComment-1430312 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.