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

Regex

Expand Messages
  • Zabil Cheriya Maliackal
    Hello there, I want to loop through a file read the lines one by one. Now I want my perl program to differentiate between string and numbers. Now could anyone
    Message 1 of 10 , Feb 18 10:37 PM
    • 0 Attachment
      Hello there,
      I want to loop through a file read the lines one by one.
      Now I want my perl program to differentiate between string and numbers.
      Now could anyone provide me a regular expression which will do that for me.
      Numbers combined string is considered as string.
      Please help me.
      Zabil
    • daymobrew@yahoo.com
      To give you a complete regular expression one would have to know the patterns in the data. You can use d to match a digit, D to not match a digit w
      Message 2 of 10 , Feb 18 10:58 PM
      • 0 Attachment
        To give you a complete regular expression one would have to know the
        patterns in the data.
        You can use '\d' to match a digit, '\D' to not match a digit
        '\w' matches an alphanumeric while [A-Za-z] matches letters (as does
        [:alpha:]
        You can use '*' and other things to match 0, 1 or more occurances of
        the item just matched.
        The "perlre" (Perl RegEx) lists everything about reg ex.

        --- In perl-beginner@y..., Zabil Cheriya Maliackal <zabilcm@m...>
        wrote:
        > Hello there,
        > I want to loop through a file read the lines one by one.
        > Now I want my perl program to differentiate between string and
        numbers.
        > Now could anyone provide me a regular expression which will do that
        for me.
        > Numbers combined string is considered as string.
        > Please help me.
        > Zabil
      • r&d@thomsondigital.com
        Hi all, I am new in PERL and trying my hands in regular expression. Below is my PERL which is actually working in XML input, in which I need to remove all the
        Message 3 of 10 , Apr 7, 2006
        • 0 Attachment
          Hi all,

          I am new in PERL and trying my hands in regular expression. Below is my
          PERL which is actually working in XML input, in which I need to remove all
          the punctuation except few of them. As it is XML, I also have to ignore
          all the tags.

          e.g. If the var is
          xxxxx; xx, xxxxxxxx ; XXx <ab:ddd>XXXXX</ab:ddd>xxxxxxxxxxx

          The output should be

          xxxxx xx xxxxxxxx ; XXx <ab:ddd>XXXXX</ab:ddd>xxxxxxxxxxx

          For punctuation its works perfect, but I am struggling with markups. Any
          help in this regard is highly appreciated.


          my $stringtoclean = $var_to_remove_punc_from;

          #<!-- @note Any character that is not a word character, a digit, any space
          character, a hyphen, or an apostrophe is removed from the parameter. -->

          $stringtoclean =~ s/[^\w\d\s-'`&;\/]//g;

          return $stringtoclean;



          Best,
          Pankaj Chaturvedi

          [Non-text portions of this message have been removed]
        • kapil v
          I read in a file with 5 csc. #!/usr/bin/perl $expect=qr/([^,]+),([^,]+),([^,]),([^,]+),(^,]+)/; foreach ( ){ $string=~/$expect/ and
          Message 4 of 10 , Jun 4, 2007
          • 0 Attachment
            I read in a file with 5 csc.

            #!/usr/bin/perl
            $expect=qr/([^,]+),([^,]+),([^,]),([^,]+),(^,]+)/;
            foreach (<>){
            $string=~/$expect/ and $rule="$1++,uc($2),uc($3),$4,uc($5),$1.$2";
            print "$rule\n";
            }

            But I get uninitialized values for $1,2,...

            Here is the input file:

            1,Vikash,BE,24,MP
            2,Anshuman,Be,29,MH
            3,Rajesh,mca,29,MH

            What is wrong here ??

            Thnx.



            I know Karate, Kung fu and 47 other dangerous words.


            ---------------------------------
            To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre.

            [Non-text portions of this message have been removed]
          • Thiago Nascimento
            Your regex was corrected, but I had suggested a modification. The output can be compared. $expect = qr{([0-9]+),([^,]+),([^,]+),([^,]+),([^,]+)}; foreach
            Message 5 of 10 , Jun 4, 2007
            • 0 Attachment
              Your regex was corrected, but I had suggested a modification. The output can
              be compared.


              $expect = qr{([0-9]+),([^,]+),([^,]+),([^,]+),([^,]+)};

              foreach (<DATA>){

              chomp($_);

              $_ =~ $expect;
              $rule = "$1++,uc($2),uc($3),$4,uc($5),$1.$2";
              print "kapil_output = $rule\n";

              $num = $1;
              $rule = ++$num . ', ' . uc($2) . ', ' . uc($3) . ", $4, " . uc($5) . ",
              $1$2";
              print "other_output = $rule\n\n";
              }

              __DATA__
              1,Vikash,BE,24,MP
              2,Anshuman,Be,29,MH
              3,Rajesh,mca,29,MH


              HTH.

              On 6/4/07, kapil v <aaaaax2003@...> wrote:
              >
              > I read in a file with 5 csc.
              >
              > #!/usr/bin/perl
              > $expect=qr/([^,]+),([^,]+),([^,]),([^,]+),(^,]+)/;
              > foreach (<>){
              > $string=~/$expect/ and $rule="$1++,uc($2),uc($3),$4,uc($5),$1.$2";
              > print "$rule\n";
              > }
              >
              > But I get uninitialized values for $1,2,...
              >
              > Here is the input file:
              >
              > 1,Vikash,BE,24,MP
              > 2,Anshuman,Be,29,MH
              > 3,Rajesh,mca,29,MH
              >
              > What is wrong here ??
              >
              > Thnx.
              >
              > I know Karate, Kung fu and 47 other dangerous words.
              >
              >
              > ---------------------------------
              > To help you stay safe and secure online, we've developed the all new
              > Yahoo! Security Centre.
              >
              > [Non-text portions of this message have been removed]
              >
              >
              >



              --
              Thiago Nascimento
              perl -e '$_="tMM naaCt Feocmama_itpUilucoGa";$_.=$1,print $2 while
              s/(..)(.)//;print substr$_,1,1;'
              "...just because I don't know the meaning of my art, does not mean it has no
              meaning..." S.D.


              [Non-text portions of this message have been removed]
            • Brad Lhotsky
              If you re using CSV, why not use Text::CSV_XS: use Data::Dumper; use Text::CSV_XS; open( my $fh, r , /path/to/file ) or die unable to read from
              Message 6 of 10 , Jun 4, 2007
              • 0 Attachment
                If you're using CSV, why not use Text::CSV_XS:

                use Data::Dumper;
                use Text::CSV_XS;

                open( my $fh, 'r', '/path/to/file')
                or die "unable to read from /path/to/file: $!\n";

                my $csv = Text::CSV_XS->new();

                while ( my $line = <$fh> ) {
                my $arrray_ref $csv->parse( $line );
                print Dumper( $array_ref );
                }
                close $fh;

                On Mon, Jun 04, 2007 at 08:06:51AM +0100, kapil v wrote:
                > I read in a file with 5 csc.
                >
                > #!/usr/bin/perl
                > $expect=qr/([^,]+),([^,]+),([^,]),([^,]+),(^,]+)/;
                > foreach (<>){
                > $string=~/$expect/ and $rule="$1++,uc($2),uc($3),$4,uc($5),$1.$2";
                > print "$rule\n";
                > }
                >
                > But I get uninitialized values for $1,2,...
                >
                > Here is the input file:
                >
                > 1,Vikash,BE,24,MP
                > 2,Anshuman,Be,29,MH
                > 3,Rajesh,mca,29,MH
                >
                > What is wrong here ??
                >
                > Thnx.
                >
                > I know Karate, Kung fu and 47 other dangerous words.
                >
                > ---------------------------------
                > To help you stay safe and secure online, we've developed the all new
                > Yahoo! Security Centre.
                >
                > [Non-text portions of this message have been removed]
                >
                >

                --
                Brad Lhotsky
              • Jabir Ahmed
                i have a string like $a= this is to test working of perl ; how do i get an array of words that contain o . Regards Jabir -- Nothing is as embarrassing as
                Message 7 of 10 , Jul 18, 2007
                • 0 Attachment
                  i have a string like

                  $a='this is to test working of perl';

                  how do i get an array of words that contain 'o'.

                  Regards

                  Jabir
                  --
                  Nothing is as embarrassing as watching someone do something that you said couldn't be done. -
                  --
                  Jabir Ahmed
                  Phone: 99807 99008
                  Email jabirahmed@...

                  [Non-text portions of this message have been removed]
                • Mr. Shawn H. Corey
                  ... It depends on what you mean by words. Try: @a = $a =~ /([A-Za-z]*o[A-Za-z]*)/g; Or: @a = $a =~ /( w*o w*)/g; -- Just my 0.00000002 million dollars worth,
                  Message 8 of 10 , Jul 18, 2007
                  • 0 Attachment
                    Jabir Ahmed wrote:
                    > i have a string like
                    >
                    > $a='this is to test working of perl';
                    >
                    > how do i get an array of words that contain 'o'.

                    It depends on what you mean by words. Try:

                    @a = $a =~ /([A-Za-z]*o[A-Za-z]*)/g;

                    Or:

                    @a = $a =~ /(\w*o\w*)/g;


                    --
                    Just my 0.00000002 million dollars worth,
                    Shawn

                    "For the things we have to learn before we can do them, we learn by
                    doing them."
                    Aristotle
                  • Jabir Ahmed
                    thanx ... From: Mr. Shawn H. Corey To: perl-beginner@yahoogroups.com Sent: Wednesday, July 18, 2007 6:39 PM Subject: Re: [PBML] Regex ... It depends on what
                    Message 9 of 10 , Jul 18, 2007
                    • 0 Attachment
                      thanx
                      ----- Original Message -----
                      From: Mr. Shawn H. Corey
                      To: perl-beginner@yahoogroups.com
                      Sent: Wednesday, July 18, 2007 6:39 PM
                      Subject: Re: [PBML] Regex


                      Jabir Ahmed wrote:
                      > i have a string like
                      >
                      > $a='this is to test working of perl';
                      >
                      > how do i get an array of words that contain 'o'.

                      It depends on what you mean by words. Try:

                      @a = $a =~ /([A-Za-z]*o[A-Za-z]*)/g;

                      Or:

                      @a = $a =~ /(\w*o\w*)/g;

                      --
                      Just my 0.00000002 million dollars worth,
                      Shawn

                      "For the things we have to learn before we can do them, we learn by
                      doing them."
                      Aristotle




                      [Non-text portions of this message have been removed]
                    • kapil v
                      Hi, #!/usr/bin/perl -w my $path = shift; my $machine = shift; my (undef,$country,$property) = split / //,$path; my $xmlData = qx!./pindown.php $machine!; my
                      Message 10 of 10 , Sep 6, 2007
                      • 0 Attachment
                        Hi,
                        #!/usr/bin/perl -w
                        my $path = shift;
                        my $machine = shift;
                        my (undef,$country,$property) = split /\//,$path;
                        my $xmlData = qx!./pindown.php $machine!;
                        my @contacts = $xmlData =~ /property name=\"$property\" country=\"$country\">.+?<contact type=\"admin\">.+?<\/contact>/is;
                        #print "$&\n";
                        print @contacts;

                        This prints "1"
                        But printing $& prints a block of XML.
                        Why does the array contacts not contain the pattern matched?

                        Thanks,
                        Kapil.V

                        ---------------------------------
                        Yahoo! Answers - Get better answers from someone who knows. Tryit now.

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