regexes

Discussion in 'Perl Misc' started by Matija Papec, Apr 16, 2004.

  1. Matija Papec

    Matija Papec Guest

    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);

    :)


    --
    Matija
     
    Matija Papec, Apr 16, 2004
    #1
    1. Advertising

  2. Matija Papec

    Steven Kuo Guest

    On Fri, 16 Apr 2004, Matija Papec wrote:

    >
    > 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

    --
    Regards,
    Steven
     
    Steven Kuo, Apr 16, 2004
    #2
    1. Advertising

  3. Matija Papec

    Matija Papec Guest

    X-Ftn-To: Steven Kuo

    Steven Kuo <> wrote:

    >> 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.


    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. :)



    --
    Matija
     
    Matija Papec, Apr 17, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roedy Green

    File.separatorChar and regexes.

    Roedy Green, Aug 22, 2003, in forum: Java
    Replies:
    0
    Views:
    1,831
    Roedy Green
    Aug 22, 2003
  2. Jason Smith

    Does Python optimize regexes?

    Jason Smith, Jun 29, 2004, in forum: Python
    Replies:
    5
    Views:
    332
  3. Klaus Neuner
    Replies:
    7
    Views:
    526
    Klaus Neuner
    Jul 26, 2004
  4. Fernando Rodriguez

    Trouble with regexes

    Fernando Rodriguez, May 25, 2005, in forum: Python
    Replies:
    2
    Views:
    347
    Tim Roberts
    May 27, 2005
  5. Ara.T.Howard

    MoinMoin WikiName and python regexes

    Ara.T.Howard, Jun 8, 2005, in forum: Python
    Replies:
    6
    Views:
    1,195
    Bengt Richter
    Jun 26, 2005
Loading...

Share This Page