regexes

M

Matija Papec

If you ever come to idea making regexes more challenging, you could always
try it in php,

my $ym = 200405;
my($year, $month) = $ym =~ /^(\d{4})(\d{2})$/;

is "same" as,

$ym = 200405;
preg_match("/^(\d{4})(\d{2})$/", $ym, $tmp);
list($year, $month) = array_slice($tmp, 1);

:)
 
S

Steven Kuo

If you ever come to idea making regexes more challenging, you could always
try it in php,

my $ym = 200405;
my($year, $month) = $ym =~ /^(\d{4})(\d{2})$/;

is "same" as,

$ym = 200405;
preg_match("/^(\d{4})(\d{2})$/", $ym, $tmp);
list($year, $month) = array_slice($tmp, 1);

:)



IMO, regular expressions are unwieldy in any language, including Perl.

Here's a contender in Tcl:

% foreach { year month } [ lrange [ regexp -inline -- {^(\d{4})(\d{2})$} "200405" ] 1 end ] { break }

% puts $year
2004

% puts $month
05
 
M

Matija Papec

X-Ftn-To: Steven Kuo

Steven Kuo said:
IMO, regular expressions are unwieldy in any language, including Perl.

It's not only the regex, but the complete path from matching to puting
things in desired places. Perl is very elegant at it, and PHP is far from
elegancy.
Here's a contender in Tcl:

% foreach { year month } [ lrange [ regexp -inline -- {^(\d{4})(\d{2})$} "200405" ] 1 end ] { break }

OMG. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top