Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Regexp for email addresses.

3 views
Skip to first unread message

Abigail

unread,
Feb 14, 2007, 4:55:40 PM2/14/07
to

use 5.9.5; # In fact, you need the newest blead.


my $email_address = qr {
(?(DEFINE)
(?<addr_spec> (?&local_part) \@ (?&domain))
(?<local_part> (?&dot_atom) | (?&quoted_string))
(?<domain> (?&dot_atom) | (?&domain_literal))
(?<domain_literal> (?&CFWS)? \[ (?: (?&FWS)? (?&dcontent))* (?&FWS)?
\] (?&CFWS)?)
(?<dcontent> (?&dtext) | (?&quoted_pair))
(?<dtext> (?&NO_WS_CTL) | [\x21-\x5a\x5e-\x7e])

(?<atext> (?&ALPHA) | (?&DIGIT) | [!#\$%&'*+-/=?^_`{|}~])
(?<atom> (?&CFWS)? (?&atext)+ (?&CFWS)?)
(?<dot_atom> (?&CFWS)? (?&dot_atom_text) (?&CFWS)?)
(?<dot_atom_text> (?&atext)+ (?: \. (?&atext)+)*)

(?<text> [\x01-\x09\x0b\x0c\x0e-\x7f])
(?<quoted_pair> \\ (?&text))

(?<qtext> (?&NO_WS_CTL) | [\x21\x23-\x5b\x5d-\x7e])
(?<qcontent> (?&qtext) | (?&quoted_pair))
(?<quoted_string> (?&CFWS)? (?&DQUOTE) (?:(?&FWS)? (?&qcontent))*
(?&FWS)? (?&DQUOTE) (?&CFWS)?)

(?<word> (?&atom) | (?&quoted_string))
(?<phrase> (?&word)+)

# Folding white space
(?<FWS> (?: (?&WSP)* (?&CRLF))? (?&WSP)+)
(?<ctext> (?&NO_WS_CTL) | [\x21-\x27\x2a-\x5b\x5d-\x7e])
(?<ccontent> (?&ctext) | (?&quoted_pair) | (?&comment))
(?<comment> \( (?: (?&FWS)? (?&ccontent))* (?&FWS)? \) )
(?<CFWS> (?: (?&FWS)? (?&comment))*
(?: (?:(?&FWS)? (?&comment)) | (?&FWS)))

# No whitespace control
(?<NO_WS_CTL> [\x01-\x08\x0b\x0c\x0e-\x1f\x7f])

(?<ALPHA> [A-Za-z])
(?<DIGIT> [0-9])
(?<CRLF> \x0d \x0a)
(?<DQUOTE> ")
(?<WSP> [\x20\x09])
)

(?&addr_spec)
}x;


Abigail
--
perl -wlpe '}{$_=$.}{' file # Count the number of lines.

john.swilting

unread,
Feb 14, 2007, 10:56:27 PM2/14/07
to
Abigail wrote:

it is incredible

cmic

unread,
Feb 15, 2007, 5:42:59 PM2/15/07
to
Hello

On 14 fév, 22:55, Abigail <abig...@abigail.be> wrote:
> use 5.9.5; # In fact, you need the newest blead.
>

...skipped


> --
> perl -wlpe '}{$_=$.}{' file # Count the number of lines.

^^^^^^^^^^^^^

As a Perl beginner, i'm a bit surprised to see this working. Could you
explain why (and how) these "counter-intuitive" } and { works ? And
how come you found out this trick ? Very very curious about this.

TIA
--
Michel Marcon, SysAdmin & Perl learner

Darren Dunham

unread,
Feb 15, 2007, 7:15:53 PM2/15/07
to
cmic <cm...@caramail.com> wrote:
> On 14 fév, 22:55, Abigail <abig...@abigail.be> wrote:
>> use 5.9.5; # In fact, you need the newest blead.
>>
> ...skipped
>> --
>> perl -wlpe '}{$_=$.}{' file # Count the number of lines.
> ^^^^^^^^^^^^^

> As a Perl beginner, i'm a bit surprised to see this working. Could you
> explain why (and how) these "counter-intuitive" } and { works ? And
> how come you found out this trick ? Very very curious about this.

Take a look at the 'perlrun' perldoc for an explanation of the -p flag.
You'll note that code you supply is already within a set of brackets.

Does that make sense?
--
Darren Dunham ddu...@taos.com
Senior Technical Consultant TAOS http://www.taos.com/
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >

Abigail

unread,
Feb 16, 2007, 3:23:00 AM2/16/07
to
cmic (cm...@caramail.com) wrote on MMMMCMXVI September MCMXCIII in
<URL:news:1171579379.1...@v33g2000cwv.googlegroups.com>:
:: Hello
::
:: On 14 fйv, 22:55, Abigail <abig...@abigail.be> wrote:
:: > use 5.9.5; # In fact, you need the newest blead.
:: >
:: ...skipped
:: > --
:: > perl -wlpe '}{$_=$.}{' file # Count the number of lines.
:: ^^^^^^^^^^^^^
::
:: As a Perl beginner, i'm a bit surprised to see this working. Could you
:: explain why (and how) these "counter-intuitive" } and { works ? And

See perlrun, or do a google search for it. It has been explained
many times.

:: how come you found out this trick ? Very very curious about this.


A remark Chip Salzenberg once (in the previous century) made in
The Perl Journal.

Abigail
--
perl -wle'print"Кхуф бопфиет Ретм Ибглет"^"\x80"x24'

Michele Dondi

unread,
Feb 16, 2007, 8:05:24 AM2/16/07
to
On 15 Feb 2007 14:42:59 -0800, "cmic" <cm...@caramail.com> wrote:

>> perl -wlpe '}{$_=3D$.}{' file # Count the number of lines.


> ^^^^^^^^^^^^^
>
>As a Perl beginner, i'm a bit surprised to see this working. Could you
>explain why (and how) these "counter-intuitive" } and { works ? And
>how come you found out this trick ? Very very curious about this.

Let perl tell you:

perl -MO=Deparse -wlpe '}{$_=$.}{'

Hope this sheds some light. BTW: I was very surprised too, when I
first saw it. As it happens with most of Abigail's .sig's.


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,

Petr Vileta

unread,
Feb 16, 2007, 11:24:56 AM2/16/07
to
"Abigail" <abi...@abigail.be> píse v diskusním príspevku
news:slrnetaqep....@alexandra.abigail.be...

> cmic (cm...@caramail.com) wrote on MMMMCMXVI September MCMXCIII in
> <URL:news:1171579379.1...@v33g2000cwv.googlegroups.com>:
> :: Hello
> ::
> :: On 14 fév, 22:55, Abigail <abig...@abigail.be> wrote:
> :: > use 5.9.5; # In fact, you need the newest blead.
> :: >
> :: ...skipped
> :: > --
> :: > perl -wlpe '}{$_=$.}{' file # Count the number of lines.
> :: ^^^^^^^^^^^^^
> ::
> :: As a Perl beginner, i'm a bit surprised to see this working. Could you
> :: explain why (and how) these "counter-intuitive" } and { works ? And
>
> See perlrun, or do a google search for it. It has been explained
> many times.
>
Can you post here some link to pages where this is explained? I have Perl
5.6.1 and code not work for me, I haven't perldoc for 5.9.5 and google not
accept these characters in search phrase.

Thanks a lot.

--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)


Michele Dondi

unread,
Feb 16, 2007, 3:28:12 PM2/16/07
to
On Fri, 16 Feb 2007 17:24:56 +0100, "Petr Vileta"
<sto...@practisoft.cz> wrote:

>> :: > use 5.9.5; # In fact, you need the newest blead.

[snip]


>> :: > --
>> :: > perl -wlpe '}{$_=$.}{' file # Count the number of lines.

[snip]


>> See perlrun, or do a google search for it. It has been explained
>> many times.
>>
>Can you post here some link to pages where this is explained? I have Perl
>5.6.1 and code not work for me, I haven't perldoc for 5.9.5 and google not
>accept these characters in search phrase.

http://www.google.it/search?q=%22count+the+number+of+lines%22+abigail

However 5.9.5 was required for the code in the body of the post. The
code being discussed here was part of the .sig: I don't have a 5.6.1
available but I'm sure it will work under the latter too. Read perlrun
for your installation of Perl and you will find the answer anyway.

Abigail

unread,
Feb 16, 2007, 4:42:22 PM2/16/07
to
Petr Vileta (sto...@practisoft.cz) wrote on MMMMCMXVII September MCMXCIII
in <URL:news:er4nad$3108$1...@ns.felk.cvut.cz>:
`` "Abigail" <abi...@abigail.be> píse v diskusním príspevku
`` news:slrnetaqep....@alexandra.abigail.be...
`` > cmic (cm...@caramail.com) wrote on MMMMCMXVI September MCMXCIII in
`` > <URL:news:1171579379.1...@v33g2000cwv.googlegroups.com>:
`` > :: Hello
`` > ::
`` > :: On 14 fév, 22:55, Abigail <abig...@abigail.be> wrote:
`` > :: > use 5.9.5; # In fact, you need the newest blead.
`` > :: >
`` > :: ...skipped
`` > :: > --
`` > :: > perl -wlpe '}{$_=$.}{' file # Count the number of lines.
`` > :: ^^^^^^^^^^^^^
`` > ::
`` > :: As a Perl beginner, i'm a bit surprised to see this working. Could you
`` > :: explain why (and how) these "counter-intuitive" } and { works ? And
`` >
`` > See perlrun, or do a google search for it. It has been explained
`` > many times.
`` >
`` Can you post here some link to pages where this is explained? I have Perl
`` 5.6.1 and code not work for me, I haven't perldoc for 5.9.5 and google not
`` accept these characters in search phrase.


The sig works for Perl 5.000 and all versions since.

Abigail
--
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"

Petr Vileta

unread,
Feb 17, 2007, 8:39:00 PM2/17/07
to
Abigail wrote:
> `` > :: > perl -wlpe '}{$_=$.}{' file # Count the number of lines.
> `` > :: ^^^^^^^^^^^^^
> `` > ::
>
> The sig works for Perl 5.000 and all versions since.
>
I use ActivePerl 5.6.1 on Windows XP but your code still not work wor me.
I get this message

c:\>perl -wlpe '}{$_=$.}{' autoexec.bat
c:\>Useless use of a constant in void context at -e line 1.

Sherm Pendley

unread,
Feb 17, 2007, 8:59:13 PM2/17/07
to
"Petr Vileta" <sto...@practisoft.cz> writes:

> Abigail wrote:
>> `` > :: > perl -wlpe '}{$_=$.}{' file # Count the number of lines.
>> `` > :: ^^^^^^^^^^^^^
>> `` > ::
>>
>> The sig works for Perl 5.000 and all versions since.
>>
> I use ActivePerl 5.6.1 on Windows XP but your code still not work wor me.

perldoc -q one-liners

sherm--

--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net

Petr Vileta

unread,
Feb 17, 2007, 11:49:48 PM2/17/07
to
Sherm Pendley wrote:
> "Petr Vileta" <sto...@practisoft.cz> writes:
>
>> Abigail wrote:
>>> `` > :: > perl -wlpe '}{$_=$.}{' file # Count the number of lines.
>>> `` > :: ^^^^^^^^^^^^^
>>> `` > ::
>>>
>>> The sig works for Perl 5.000 and all versions since.
>>>
>> I use ActivePerl 5.6.1 on Windows XP but your code still not work
>> wor me.
>
> perldoc -q one-liners
>
Yes you are right. After I change single quoute to double I got different
error message :-)

c:\>perl -wlpe "}{$_=$.}{" autoexec.bat

Unmatched right curly bracket at -e line 1, at end of line
syntax error at -e line 1, near "}"
Execution of -e aborted due to compilation errors.
c:\>

I'm writting in Perl many years and uderstand what is $_ what is $. what is
{ }, but not understand what should to do } { . What is meaning by brackets
in reverse order?

Michele Dondi

unread,
Feb 18, 2007, 4:45:19 AM2/18/07
to
On Sun, 18 Feb 2007 05:49:48 +0100, "Petr Vileta"
<sto...@practisoft.cz> wrote:

>> perldoc -q one-liners
>>
>Yes you are right. After I change single quoute to double I got different
>error message :-)
>
>c:\>perl -wlpe "}{$_=$.}{" autoexec.bat
>
>Unmatched right curly bracket at -e line 1, at end of line
>syntax error at -e line 1, near "}"
>Execution of -e aborted due to compilation errors.

C:\temp>perl -wlpe "}{$_=$.}{" foo.pl
19

5.8.8 here, but really no reason why 5.6.1 shouldn't do it.

>I'm writting in Perl many years and uderstand what is $_ what is $. what is

Ouch! You're getting a real PITA: did you care following the advice
that has been given to you?!?

In <news:slrnetaqep....@alexandra.abigail.be> Abigail pointed
you to

perldoc perlrun

Did you check the latter, especially where it explains the behaviour
of -p?

He also suggested a google search. In
<news:er4nad$3108$1...@ns.felk.cvut.cz> you replied that you could not
come up with a sensible search, and in
<news:6l4ct292brb4d3jtj...@4ax.com> I replied in turn
suggesting a suitable one, that I'm repeating here:


http://www.google.it/search?q=%22count+the+number+of+lines%22+abigail

Did you check it? What's wrong with it?!?

OTOH in <news:4rabt21v08jnet2lr...@4ax.com> I suggested
a cheap recipe to have Perl tell you what's going on, which I'm also
repeating here:

perl -MO=Deparse -wlpe '}{$_=$.}{'

What did it tell you?

>{ }, but not understand what should to do } { . What is meaning by brackets
>in reverse order?

Appearently you've been "writting" Perl for many years, but you didn't
check the docs much, nor you seem to be used to. Before this goes on
fot too long, here's the explanation: the -p cmd line switch "puts
code" around the script code, whether it's in a file or supplied
through -e. Basically it puts everything in a cycle, so that e.g.

perl -pe ""

behaves like the cat command. The -l switch modifies -p in a somewhat
minor way:

C:\temp>perl -MO=Deparse -lpe ""
BEGIN { $/ = "\n"; $\ = "\n"; }
LINE: while (defined($_ = <ARGV>)) {
chomp $_;
}
continue {
print $_;
}
-e syntax OK

The code you supply in -e will go right after chomp(). If it starts
with an "unmatched" right curly, the latter won't really be unmatched,
but it will match the left one on the LINE: line. Similarly the
"unmatched" left one at the end will match the one below the chomp()
line, creating an empty block. Thus it's a trick to... trick -p into
doing something it's not really meant to.


HTH,

Petr Vileta

unread,
Feb 18, 2007, 8:50:31 AM2/18/07
to

"Michele Dondi" <bik....@tiscalinet.it> píse v diskusním príspevku
news:6f6gt21ftva6gsut2...@4ax.com...

> On Sun, 18 Feb 2007 05:49:48 +0100, "Petr Vileta"
> <sto...@practisoft.cz> wrote:
>
> perl -MO=Deparse -wlpe '}{$_=$.}{'
>
> What did it tell you?
>
This help me to understand. I never used module Deparse and don't know why
:-)

> HTH,
> Michele
Thank you for explanation. I'm using Perl many years but for web scripts
(cgi) not for one line scripts.
Human are learning along all life :-)

Michele Dondi

unread,
Feb 19, 2007, 6:35:26 AM2/19/07
to
On Sun, 18 Feb 2007 14:50:31 +0100, "Petr Vileta"
<sto...@practisoft.cz> wrote:

>> perl -MO=Deparse -wlpe '}{$_=$.}{'
>>
>> What did it tell you?
>>
>This help me to understand. I never used module Deparse and don't know why

It's B::Deparse.

>Thank you for explanation. I'm using Perl many years but for web scripts
>(cgi) not for one line scripts.

Well, one liners are generally "simpler". Except when using witty obfu
or golf(-like) techniques on purpose, that is.

>Human are learning along all life :-)

I wholeheartedly second that. In the meanwhile I also apologize if my
post seemed overly aggressive in some points. I hope to have given you
some tips about how not to be spoon fed in the future.

cmic

unread,
Feb 19, 2007, 7:51:38 AM2/19/07
to
On 18 fév, 10:45, Michele Dondi <bik.m...@tiscalinet.it> wrote:
> On Sun, 18 Feb 2007 05:49:48 +0100, "Petr Vileta"
>
> <sto...@practisoft.cz> wrote:
> >> perldoc -q one-liners
>
[...]

>
> OTOH in <news:4rabt21v08jnet2lr...@4ax.com> I suggested
> a cheap recipe to have Perl tell you what's going on, which I'm also
> repeating here:
>
> perl -MO=Deparse -wlpe '}{$_=$.}{'

Really helpfull. THX

>
> What did it tell you?
>
> >{ }, but not understand what should to do } { . What is meaning by brackets
> >in reverse order?
>

[...]


> The code you supply in -e will go right after chomp(). If it starts
> with an "unmatched" right curly, the latter won't really be unmatched,
> but it will match the left one on the LINE: line. Similarly the
> "unmatched" left one at the end will match the one below the chomp()
> line, creating an empty block. Thus it's a trick to... trick -p into
> doing something it's not really meant to.

I read "perldoc perlrun", but not enough carefully. Next time...
But I couldn't imagine such tricks ! Maybe I'm a naive programmer...

THX Michele
BTW, your signature worth it, too !
--
michel marcon

Michele Dondi

unread,
Feb 19, 2007, 12:24:42 PM2/19/07
to
On 19 Feb 2007 04:51:38 -0800, "cmic" <cm...@caramail.com> wrote:

>THX Michele
>BTW, your signature worth it, too !

Well, I've been only an occasional obfu player. If you need an
explanation, it's available at <http://perlmonks.org/?node_id=410408>.

Ted Zlatanov

unread,
Mar 7, 2007, 6:08:24 PM3/7/07
to
On 14 Feb 2007 21:55:40 GMT Abigail <abi...@abigail.be> wrote:

A> use 5.9.5; # In fact, you need the newest blead.


A> my $email_address = qr {
A> (?(DEFINE)
A> (?<addr_spec> (?&local_part) \@ (?&domain))
...
A> (?&addr_spec)
A> }x;

I have a question (to you or anyone else informed), as I don't follow
the latest Perl 5 changes and features: is this grammar syntax
experimental, or will it definitely remain in Perl 5 at this point? I
don't mind the latest blead, but I don't want to commit my own code to
it if the feature is experimental.

Thanks for the code, it was fascinating.

Ted

Abigail

unread,
Mar 7, 2007, 6:14:49 PM3/7/07
to
Ted Zlatanov (t...@lifelogs.com) wrote on MMMMCMXXXVI September MCMXCIII
in <URL:news:g69vehc...@dhcp-65-162.kendall.corp.akamai.com>:

Well, until 5.10 anything could change. But with 5.10 getting close,
it seems unlikely there will be significant changes to the features
I used in the regexp.

Abigail
--
$_ = "\x3C\x3C\x45\x4F\x54" and s/<<EOT/<<EOT/e and print;
Just another Perl Hacker
EOT

0 new messages