Re: Regular Expression help

From: Date: Wed, 16 Apr 2003 15:19:05 +0000
Subject: Re: Regular Expression help
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-144128@lists.php.net to get a copy of this message
Thanks Jack. I looked through the code again this morning with fresh eyes, and found the problem to be with the variable I was testing against instead of with the pattern. I was testing against $temp when I sould have been using $temp[$i]. If you hear about some guy in the news tonight who spent his whole work day beating his head against his desk while muttering, "stupid, stupid", that will be me. :) Jack Dempsey wrote:
hey john, just tried this in php and perl, and it seems to give the results you want: <? $bad = "# ARIN WHOIS data and confirm the accuracy of the information provided"; $bad1 = "Resource Type|Resource Name|Resource Handle|Parent Resource"; $good = "A|IANA-RSVD2|AS64512||64512|65535|IANA|Internet Assigned Numbers"; $good1 = "V4|RESERVED-1|NET-0-0-0-0-1||0.0.0.0|0.255.255.255|IANA|Internet"; $pattern = "/^[a-zA-Z0-9]+\|/"; $res = preg_match($pattern, $good1, $matches); if($res){
        print "match<p>";
        print_r($matches);
} else {
        print "no match";
} ?> don't know if the _ is needed as well though... jack
-----Original Message----- From: John Nichel [mailto:jnichel@by-tor.com] Sent: Tuesday, April 15, 2003 5:37 PM To: php-general@lists.php.net Subject: [PHP] Regular Expression help I am trying to match a line which starts with an alpha-numeric "word" followed by a pipe ( | ), however my regex's seem to be a bit off When I use the following... ^[A-Za-z_0-9]+\| It matches none of the lines. And when I remove the escape from the pipe, it matches everything in the world ( lines that start with #, lines that start with multiple words (seperated by spaces) then by a pipe, etc. examples of lines I don't want to match.. # ARIN WHOIS data and confirm the accuracy of the information provided Resource Type|Resource Name|Resource Handle|Parent Resource And an example of lines that I do want to match...... A|IANA-RSVD2|AS64512||64512|65535|IANA|Internet Assigned Numbers V4|RESERVED-1|NET-0-0-0-0-1||0.0.0.0|0.255.255.255|IANA|Internet Can anyone help shed some light on this? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#144128) next »