RE: [PHP] Regular Expression help
| From: | Jack Dempsey | Date: | Wed, 16 Apr 2003 00:32:33 +0000 |
| Subject: | RE: [PHP] Regular Expression help | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-144042@lists.php.net to get a copy of this message | ||
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
>
>