Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] regexp

Expand Messages
  • Shawn H Corey
    ... Yes, try: m{ # start of match - # match a hyphen D* # skip non-digits ( d) # capture first digit D* # skip non-digits ( d) # capture
    Message 1 of 9 , Nov 4, 2011
    • 0 Attachment
      On 11-11-04 03:46 PM, Weder Prado wrote:
      > I am learning perl and I need to create a regexp that extract only the 4
      > digits after the "-"
      > Below the string:
      >
      > 20111014-18:00:14.474 : 8=FIX.4.2 9=68 35=1 34=1074 49=FIX134800
      > 52=20111014-18:00:14.474 56=BVMF 112=TEST 10=191
      >
      > Is it possible?

      Yes, try:

      m{ # start of match
      \- # match a hyphen
      \D* # skip non-digits
      (\d) # capture first digit
      \D* # skip non-digits
      (\d) # capture second digit
      \D* # skip non-digits
      (\d) # capture third digit
      \D* # skip non-digits
      (\d) # capture fourth digit
      }msx # end of match


      See:
      perldoc perlretut
      perldoc perlre


      --
      Just my 0.00000002 million dollars worth,
      Shawn

      Confusion is the first step of understanding.

      Programming is as much about organization and communication
      as it is about coding.

      The secret to great software: Fail early & often.

      Eliminate software piracy: use only FLOSS.

      "Make something worthwhile." -- Dear Hunter
    • Yatin Jadhav
      Try this it works........... $a = 20111014-18:00:14.474 : 8=FIX.4.2 9=68 35=1 34=1074 49=FIX13480052=20111014-18:00:14.474 56=BVMF 112=TEST 10=191 ; @b =
      Message 2 of 9 , Nov 5, 2011
      • 0 Attachment
        Try this it works...........

        $a = "20111014-18:00:14.474 : 8=FIX.4.2 9=68 35=1 34=1074 49=FIX13480052=20111014-18:00:14.474 56=BVMF 112=TEST 10=191";
        @b = split(m/-/,$a);
        @c = split(m//,$b[1]);
        print ("$c[0]$c[1]$c[2]$c[3]\n");



         
        Regards,
        Yatin Jadhav



        ________________________________
        From: Shawn H Corey <shawnhcorey@...>
        To: perl-beginner@yahoogroups.com
        Sent: Saturday, November 5, 2011 3:10 AM
        Subject: Re: [PBML] regexp


         
        On 11-11-04 03:46 PM, Weder Prado wrote:
        > I am learning perl and I need to create a regexp that extract only the 4
        > digits after the "-"
        > Below the string:
        >
        > 20111014-18:00:14.474 : 8=FIX.4.2 9=68 35=1 34=1074 49=FIX134800
        > 52=20111014-18:00:14.474 56=BVMF 112=TEST 10=191
        >
        > Is it possible?

        Yes, try:

        m{ # start of match
        \- # match a hyphen
        \D* # skip non-digits
        (\d) # capture first digit
        \D* # skip non-digits
        (\d) # capture second digit
        \D* # skip non-digits
        (\d) # capture third digit
        \D* # skip non-digits
        (\d) # capture fourth digit
        }msx # end of match

        See:
        perldoc perlretut
        perldoc perlre

        --
        Just my 0.00000002 million dollars worth,
        Shawn

        Confusion is the first step of understanding.

        Programming is as much about organization and communication
        as it is about coding.

        The secret to great software: Fail early & often.

        Eliminate software piracy: use only FLOSS.

        "Make something worthwhile." -- Dear Hunter



        [Non-text portions of this message have been removed]
      • timothy adigun
        Hi Prado, ... output, instead, the output will be 18:0. I suppose you didn t put the *:* into consideration as part of the output, since you are you *split* on
        Message 3 of 9 , Nov 5, 2011
        • 0 Attachment
          Hi Prado,

          Yatin Jadhav <yatinjdhv@...> wrote:

          > **
          >
          >
          > Try this it works...........
          >
          > $a = "20111014-18:00:14.474 : 8=FIX.4.2 9=68 35=1 34=1074
          > 49=FIX13480052=20111014-18:00:14.474 56=BVMF 112=TEST 10=191";
          > @b = split(m/-/,$a);
          > @c = split(m//,$b[1]);
          > print ("$c[0]$c[1]$c[2]$c[3]\n");
          >
          > print ("$c[0]$c[1]$c[2]$c[3]\n"); will not print 18:00, if that is the
          output, instead, the output will be 18:0. I suppose you didn't put the *:*
          into consideration as part of the output, since you are you *split* on the
          $b[1] according to your script.

          You could also write *print ("$c[0]$c[1]$c[2]$c[3]\n"); * more clearly as
          *print @c[ 0 .. 4 ];*, which i believe will be more error prone.

          Do one really have to go through all the trouble of array and split when,
          one could just use substitution and regex to extract what you want? Anyway,
          I guess, there is more than one way to do it!
          Try this:

          #!/usr/bin/perl -wl
          use strict;

          my $a =
          "20111014-18:00:14.474 : 8=FIX.4.2 9=68 35=1 34=1074
          49=FIX13480052=20111014-18:00:14.474 56=BVMF 112=TEST 10=191";

          ( my $new_val = $a ) =~ s/^(\d+)-(\d{2}:\d{2})(?:.*)/$2/imgx;
          print $new_val;
          __END__
          OUTPUT: 18:00
          --
          Tim


          [Non-text portions of this message have been removed]
        • timothy adigun
          ... output, instead, the output will be 18:0. I suppose you didn t put the *:* into consideration as part of the output, since you are you *split* on the $b[1]
          Message 4 of 9 , Nov 5, 2011
          • 0 Attachment
            Yatin Jadhav <yatinjdhv@...> wrote:

            >
            >
            > Try this it works...........
            >
            > $a = "20111014-18:00:14.474 : 8=FIX.4.2 9=68 35=1 34=1074
            > 49=FIX13480052=20111014-18:00:14.474 56=BVMF 112=TEST 10=191";
            > @b = split(m/-/,$a);
            > @c = split(m//,$b[1]);
            > print ("$c[0]$c[1]$c[2]$c[3]\n");
            >
            > print ("$c[0]$c[1]$c[2]$c[3]\n"); will not print 18:00, if that is the
            output, instead, the output will be 18:0. I suppose you didn't put the *:*
            into consideration as part of the output, since you are you *split* on the
            $b[1] according to your script.

            You could also write *print ("$c[0]$c[1]$c[2]$c[3]\n"); * more clearly as
            *print @c[ 0 .. 4 ];*, which i believe will be more error prone free.

            Do one really have to go through all the trouble of array and split when,
            one could just use substitution and regex to extract what you want? Anyway,
            I guess, there is more than one way to do it!
            Try this:

            #!/usr/bin/perl -wl
            use strict;

            my $a =

            "20111014-18:00:14.474 : 8=FIX.4.2 9=68 35=1 34=1074
            49=FIX13480052=20111014-18:00:14.474 56=BVMF 112=TEST 10=191";

            ( my $new_val = $a ) =~ s/^(\d+)-(\d{2}:\d{2})(?:.*)/$2/imgx;
            print $new_val;
            __END__
            OUTPUT: 18:00
            --
            Tim


            [Non-text portions of this message have been removed]
          Your message has been successfully submitted and would be delivered to recipients shortly.