Re: Re: Re: Re[4]: Популяризация
Евгений Карпенко
notformat at gmail.com
Sun Aug 8 13:08:33 PDT 2010
>
> Более интересный пример: IP-адреса, Perl5
> файл IPType.pm
>
> package IPType;
> use Regexp::Common 2.105;
> use MooseX::Types::Moose qw( Str );
> use MooseX::Types -declare => [ qw(IP) ];
>
> subtype IP, as Str, where {
> $_ =~ /\A $RE{net}{IPv4} \z/msx
> }, message {
> "'$_' is not a valid IP";
> };
>
> файл typed.pl
>
> use IPType qw/IP/;
> use MooseX::Lexical::Types qw/IP/;
>
> my IP $foo; # declare typed variable
> $foo = '192.168.1.1'; # works
> $foo = 'bar'; # fails
import java.util.regex.*;
public class TestRegexp {
public static final Pattern pattern = Pattern.compile
("[a-zA-Z]{1}[a-zA-Z\d\u002E\u005F]+@([a-zA-Z]+\u002E){1,2}((net)|(com)|(org))");
public static void doMatch(String word) {
String output = "Validation for " + word;
Matcher matcher = pattern.matcher(word);
if (matcher.matches())
output += " passed."
else
output += " not passed."
System.out.println(output);
}
public static void main(String[] args) {
doMatch("c0nst at money.simply.net");
doMatch("somebody at dev.com.ua");
doMatch("Name.Sur_name at gmail.com");
doMatch("useR33 at somewhere.in.the.net");
}
}
Не в тему АЙПИ а в тему регулярных выражений.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/kiev-pm/attachments/20100809/1ed66a84/attachment.html>
More information about the Kiev-pm
mailing list