Backreferencing through two sets of slashes

Discussion in 'Perl Misc' started by Eric Smith, Nov 6, 2011.

  1. Eric Smith

    Eric Smith Guest

    Hi

    if ( $foo =~ /(\d\d)-(\d\d)-\d\d\d\d/ and $bar =~ /(\d?\d):(\d\d):(\d
    \d)/ )
    {
    # How do I match here the the two fields of $foo ?
    # Or is it not possible in a single construction?
    # $bar of course gives its ($hours, $minutes, $seconds) = $1, $2 and
    $3
    }

    Thanks

    Eric Smith
    Eric Smith, Nov 6, 2011
    #1
    1. Advertising

  2. Eric Smith

    C.DeRykus Guest

    On Nov 6, 11:53 am, Eric Smith <> wrote:
    > Hi
    >
    > if ( $foo =~ /(\d\d)-(\d\d)-\d\d\d\d/ and $bar =~ /(\d?\d):(\d\d):(\d
    > \d)/ )
    > {
    > # How do I match here the the two fields of $foo ?
    > # Or is it not possible in a single construction?
    > # $bar of course gives its ($hours, $minutes, $seconds) = $1, $2 and
    > $3
    >
    > }


    You may need to clarify or provide some actual
    data... If, possibly, you're trying to match
    alternate date formats, you might use something
    such as this:

    if ( /(?| (\d\d) - (\d\d) - (\d{4}) # format 1
    | # or
    (\d\d?) : (\d\d) : (\d{4}) # format 2
    )/x )
    {
    print "\$1=$1 \$2=$2 \$3=$3\n";
    }

    * see perlre for meaning of (?|pattern) "branch
    reset pattern)

    --
    Charles DeRykus
    C.DeRykus, Nov 8, 2011
    #2
    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. qazmlp
    Replies:
    5
    Views:
    679
    Michael Dunn
    Apr 7, 2004
  2. Peter Horlock
    Replies:
    2
    Views:
    299
  3. Dan Wilkin
    Replies:
    1
    Views:
    250
    robic0
    Jul 17, 2006
  4. java
    Replies:
    7
    Views:
    270
  5. Eric smith

    backreferences to two sets of slashes

    Eric smith, Nov 6, 2011, in forum: Perl Misc
    Replies:
    1
    Views:
    206
    Helmut Richter
    Nov 6, 2011
Loading...

Share This Page