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

RE: [PBML] Usage of regular expression?

Expand Messages
  • Ron Goral
    ... Ummmmmmmmmmmm Good thing that wasn t production code. (weak smile). Please disregard this ill-considered contribution.
    Message 1 of 10 , Dec 2, 2004
      > -----Original Message-----
      > From: eman [mailto:bloodpet@...]
      > Sent: Thursday, December 02, 2004 7:08 PM
      > To: perl-beginner@yahoogroups.com; Goral, Ron
      > Subject: Re: [PBML] Usage of regular expression?
      >
      >
      >
      > On Thu, 2 Dec 2004 18:55:25 -0600, Ron Goral
      > <subscriptions@...> wrote:
      > >
      > >
      > > Another method would be something like:
      > >
      > > for a single word -
      > > /a\w?e\w?i\w?o\w?u/;
      > >
      > > for a line of text with any chars in between -
      > >
      > > /a.?e.?i.?o.?u/
      > >
      > > Peace -
      > > Ron
      > >
      > >
      >
      > But wouldn't those require that the vowels (a, e, i, o, u) are in
      > that order?

      Ummmmmmmmmmmm

      Good thing that wasn't production code. (weak smile).

      Please disregard this ill-considered contribution.
    • Charles K. Clarkson
      ... Why use the /g modifier in an if ? The first match is all we need for truth. Other matches don t matter. Also $1 will never be true if the test fails.
      Message 2 of 10 , Dec 2, 2004
        Ron Goral <subscriptions@...> wrote:

        : K. This one I tried first. ;P
        :
        :
        : # All the vowels, not in order
        : my $text = qq[Every good boy deserves favor.];
        : # All except a, not in order
        : my $other = qq[bcdfeghijko if You think of it.];
        :
        : if ($text =~ /([AEIOUaeiou])/g){print qq[Got text - $1.] if $1;}

        Why use the /g modifier in an 'if'? The first match
        is all we need for truth. Other matches don't matter. Also
        $1 will never be true if the test fails.

        print qq[Got text - $1.] if $text =~ /([AEIOUaeiou])/;


        : if ($other =~ /[AEIOUaeiou]/g){print qq[Got other - $1.] if $1;}

        There is no capture here. $1 will always be false.
        Nothing will ever print.


        HTH,

        Charles K. Clarkson
        --
        Mobile Homes Specialist
        254 968-8328
      • Ron Goral
        ... Correct about the g modifier. But, this is not a complete program, just an illustration of how to capture the match. What to do when it matches or not is
        Message 3 of 10 , Dec 2, 2004
          > -----Original Message-----
          > From: Charles K. Clarkson [mailto:cclarkson@...]
          > Sent: Thursday, December 02, 2004 7:51 PM
          > To: perl-beginner@yahoogroups.com
          > Subject: RE: [PBML] Usage of regular expression?
          >
          >
          >
          > Ron Goral <subscriptions@...> wrote:
          >
          > : K. This one I tried first. ;P
          > :
          > :
          > : # All the vowels, not in order
          > : my $text = qq[Every good boy deserves favor.];
          > : # All except a, not in order
          > : my $other = qq[bcdfeghijko if You think of it.];
          > :
          > : if ($text =~ /([AEIOUaeiou])/g){print qq[Got text - $1.] if $1;}
          >
          > Why use the /g modifier in an 'if'? The first match
          > is all we need for truth. Other matches don't matter. Also
          > $1 will never be true if the test fails.
          >
          > print qq[Got text - $1.] if $text =~ /([AEIOUaeiou])/;
          >
          >
          > : if ($other =~ /[AEIOUaeiou]/g){print qq[Got other - $1.] if $1;}
          >
          > There is no capture here. $1 will always be false.
          > Nothing will ever print.
          >
          >
          > HTH,
          >
          > Charles K. Clarkson
          > --
          > Mobile Homes Specialist
          > 254 968-8328

          Correct about the g modifier. But, this is not a complete program, just an
          illustration of how to capture the match. What to do when it matches or not
          is up to the implementor.
        • J.E. Cripps
          ... all five? or words with any selection (aaiio, aeeou, eeeio)? ... Hint: /cat/ will match catalogue , concatenate wildcat ... this is IIRC perlrequick
          Message 4 of 10 , Dec 2, 2004
            > I am doing a exercise which requires me to find out all the words
            > that contains five vowels(a, e, I, o, u) from a text file.

            all five? or words with any selection (aaiio, aeeou, eeeio)?


            > I wrote a the following code to test it.
            > While(<>)
            > {
            > print if /aeiou/
            > }

            Hint: /cat/ will match "catalogue", "concatenate"
            "wildcat" ... this is IIRC perlrequick and perlretut.
            (the perldocs for regular expressions)
          • Mike Flannigan
            ... I would do: while ( ) { next unless tr/a//; next unless tr/e//; next unless tr/i//; next unless tr/o//; next unless tr/u//; print; } Mike
            Message 5 of 10 , Dec 3, 2004
              perl-beginner@yahoogroups.com wrote:

              >
              > Date: Thu, 02 Dec 2004 23:53:52 -0000
              > From: "Jeff Shu" <santa98bn@...>
              > Subject: Usage of regular expression?
              >
              > Hello everyone:
              >
              > Hello
              >
              > I am doing a exercise which requires me to find out all the words
              > that contains five vowels(a, e, I, o, u) from a text file.
              >
              > I wrote a the following code to test it.
              > While(<>)
              > {
              > print if /aeiou/
              > }
              >
              > but the result didn't show any words that contains five vowels. I
              > am
              > wondering what's wrong the my regular expression. Please give me
              > some
              > suggestions. Thanks!
              > Jeff
              > 12-02-04

              I would do:

              while (<>) {
              next unless tr/a//;
              next unless tr/e//;
              next unless tr/i//;
              next unless tr/o//;
              next unless tr/u//;
              print;
              }


              Mike
            Your message has been successfully submitted and would be delivered to recipients shortly.