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

Re: [PBML] Re: pattern matching

Expand Messages
  • Pavlos Parissis
    Hi, This is very nice idea but I want to find a regex to match the directories of files because in the same files I will have lines begging with ! and the dirs
    Message 1 of 25 , Jan 1, 2004
    • 0 Attachment
      Hi,
      This is very nice idea but I want to find a regex to match the directories of
      files because
      in the same files I will have lines begging with ! and the dirs or files and maybe
      something else.

      For instance:
      !/foo/.foo
      /foo
      =/one/two

      So, I want to find a very good regex to match the dirs or file.
      So for it seems to work but I would like to hear more ideas.

      THanks a lot for the tip
      PAvlos

      On Wed, 31 Dec 2003 21:38:48 -0000 "chcst53" <charley@...> wrote:
      > --- In perl-beginner@yahoogroups.com, Pavlos Parissis
      > <p_pavlos@f...> wrote:
      > > Hello all
      > > I have a file with:
      > [snipped]
      > > Am I going to miss anything?
      >
      > Hello Pavlos
      >
      > Instead of trying to match with a regular expression, you might want
      > to use split to get the 2 fields in your data.
      >
      > Cheers,
      > Chris
      >
      > #!/usr/bin/perl
      > use strict;
      > use warnings;
      >
      > while (<DATA>) {
      > chomp;
      > my ($v1, $v2) = split / \+/;
      > print "val1=$v1 val2=$v2\n";
      > }
      >
      > __DATA__
      > /home +trrr
      > /.ssh +tr
      > /home/.ssh +rt
      > /home/ssh.conf +rrrr
      > /home/conf.conf +rrrr
      >
      > ## Output ##
      > C:\perlp>perl try.pl
      > val1=/home val2=trrr
      > val1=/.ssh val2=tr
      > val1=/home/.ssh val2=rt
      > val1=/home/ssh.conf val2=rrrr
      > val1=/home/conf.conf val2=rrrr
      >
      >
      >
      > Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html
      >
      >
      > Yahoo! Groups Links
      >
      > To visit your group on the web, go to:
      > http://groups.yahoo.com/group/perl-beginner/
      >
      > To unsubscribe from this group, send an email to:
      > perl-beginner-unsubscribe@yahoogroups.com
      >
      > Your use of Yahoo! Groups is subject to:
      > http://docs.yahoo.com/info/terms/
      >
      >


      --
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      I love having the feeling of being in control
      while i have the sensation of speed

      The surfer of life
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      GnuPG Key: FB1E6AE7
      Fingerprint A9AE EA0C EE1F FBD0 5B6F 3F77 2782 EFE2 FB1E 6AE7
      Get my key here: http://users.hol.gr/~p_pavlos/pubpgpkey.txt
    • Pavlos Parissis
      ... (.*?) what exactly will this match? ... -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I love having the feeling of being in control while i have the sensation of speed
      Message 2 of 25 , Jan 1, 2004
      • 0 Attachment
        On Wed, 31 Dec 2003 16:37:16 -0500 Brad Lhotsky <brad@...> wrote:
        > Why won't this work:
        >
        > my ($directory,$flags) = split /\s+/, $line;
        >
        > Neither one supports spaces in file names, you'd use this:
        >
        > my ($directory,$flags) = ($line =~ /(.*)\s+(\S+)$/);
        >
        > Two important things about the above regular expression.
        > 1) .* is a greedy match, it matches to the end of the line and "gives
        > up" characters to satisfy the rest of the regular expression. Often
        > this is the "accidental" desired effect, pay attention to greediness.
        > 2) I like to use anchors, it helps the regex and you understand what
        > exactly we're talking about. If someone replaced your greedy operator
        > with its non-greedy counterpart (.*?) to avoid using greedy operators
        > because they "heard from someone that greedy operators are bad", the
        > regex would STILL match what you intended, only much much slower.

        (.*?) what exactly will this match?

        > Enjoy,
        >
        > On Wed, Dec 31, 2003 at 10:19:29PM +0200, Pavlos Parissis wrote:
        > > Hello all
        > > I have a file with:
        > > /home +trrr
        > > /.ssh +tr
        > > /home/.ssh +rt
        > > /home/ssh.conf +rrrr
        > > /home/conf.conf +rrrr
        > > Is the following the best way to match lines and store it?
        > > $line =~ m/^(\/[\/a-zA-Z0-9_.]+)\s+\+(\w+)$/
        > > Am I going to miss anything?
        > >
        > >
        > > Happy new Year to all
        > >
        > > Pavlos
        > >
        > > --
        > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        > > I love having the feeling of being in control
        > > while i have the sensation of speed
        > >
        > > The surfer of life
        > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        > > GnuPG Key: FB1E6AE7
        > > Fingerprint A9AE EA0C EE1F FBD0 5B6F 3F77 2782 EFE2 FB1E 6AE7
        > > Get my key here: http://users.hol.gr/~p_pavlos/pubpgpkey.txt
        > >
        > > Unsubscribing info is here:
        > > http://help.yahoo.com/help/us/groups/groups-32.html
        > >
        > > Yahoo! Groups Links
        > >
        > > To visit your group on the web, go to:
        > > http://groups.yahoo.com/group/perl-beginner/
        > >
        > > To unsubscribe from this group, send an email to:
        > > perl-beginner-unsubscribe@yahoogroups.com
        > >
        > > Your use of Yahoo! Groups is subject to:
        > > http://docs.yahoo.com/info/terms/
        > >
        > >
        >
        > --
        > Brad Lhotsky <brad@...>
        >
        > Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html
        >
        >
        > Yahoo! Groups Links
        >
        > To visit your group on the web, go to:
        > http://groups.yahoo.com/group/perl-beginner/
        >
        > To unsubscribe from this group, send an email to:
        > perl-beginner-unsubscribe@yahoogroups.com
        >
        > Your use of Yahoo! Groups is subject to:
        > http://docs.yahoo.com/info/terms/
        >
        >


        --
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        I love having the feeling of being in control
        while i have the sensation of speed

        The surfer of life
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        GnuPG Key: FB1E6AE7
        Fingerprint A9AE EA0C EE1F FBD0 5B6F 3F77 2782 EFE2 FB1E 6AE7
        Get my key here: http://users.hol.gr/~p_pavlos/pubpgpkey.txt
      • Brad Lhotsky
        ... By itself? Nothing. In Context, whatever it HAS to match to satisfy the rest of the regular expression. It s a non-greedy (lazy) match. I wrote an intro
        Message 3 of 25 , Jan 1, 2004
        • 0 Attachment
          On Thu, Jan 01, 2004 at 04:54:58PM +0200, Pavlos Parissis wrote:
          > > 2) I like to use anchors, it helps the regex and you understand what
          > > exactly we're talking about. If someone replaced your greedy operator
          > > with its non-greedy counterpart (.*?) to avoid using greedy operators
          > > because they "heard from someone that greedy operators are bad", the
          > > regex would STILL match what you intended, only much much slower.
          >
          > (.*?) what exactly will this match?
          >

          By itself? Nothing. In Context, whatever it HAS to match to satisfy the
          rest of the regular expression. It's a non-greedy (lazy) match.

          I wrote an intro to Reg Ex for co-workers a while back:
          http://divisionbyzero.net/~brad/code/regex.txt

          This expression is covered in there ;)

          Enjoy,

          --
          Brad Lhotsky <brad@...>
        • Pavlos Parissis
          Hello all, I think I found an nice solution. so let me remind you the story a file with the following /mnt Myrule /koko/ 2rule dd/dd ff /etc/passwd tete
          Message 4 of 25 , Jan 2, 2004
          • 0 Attachment
            Hello all,

            I think I found an nice solution.
            so let me remind you the story
            a file with the following
            /mnt Myrule
            /koko/ 2rule
            dd/dd ff
            /etc/passwd tete
            /goo/goo r+t
            !/var/log/messages.*
            /mnt/extra/system_backup/etc t+t+t
            !/mnt/extra/system_backup/etc/reoback
            =/tmp g+gg
            =/foo r+r
            =ho/ddd t+t
            =/bar My
            =/slice my

            it looks like the side.conf file
            and I want to grab only the line that start with full path of "dir or files" and
            word+word or a word only with the capital first letter.
            Valid lines are all the lines that start with ! or = or /
            and for each of the abover correct lines the path must be the full path. The
            problem
            here is that I can not find a regex to math only valid filesystem paths.
            Now if the the path is like this /foo\ff it will be matched:(
            Any ideas about this?
            The code is this

            18 open(CONF,"<$conf");
            19 while (defined($line = <CONF>)) {
            20 my $path;
            21 my $flags;
            22 chomp($line);
            23 next if ($line =~ /^#.*/); # no comments.
            24 next if ($line =~ /^\s+/); # no leading white.
            25 next if ($line =~ /^\s+$/); # no trailing white.
            26 next unless length $line; # null and empty lines.
            27 ($path,$flags) = split /\s+/, $line;
            28 if ( !( $path =~ m/^(!|\/|=)/) ){
            29 print "wrong format $path\n";
            30 next;
            31 }
            32 if ( defined($flags) and $flags =~ /\S/ ) { # accept only flags with
            this w+w+w or this First.
            33 next if ( (!($flags =~ /^(\w\+)+\w$/)) and (!($flags =~
            /^[A-Z]\w+/)) );
            34 }
            35 if ($path =~ m/^(!)(\/.*)/) {
            36 push @excluded_dirs, $2;
            37 next;
            38 } elsif ($path =~ m/^(=)(\/.*)$/) {
            39 $dirs_only{"$2"} = "$flags";
            40 next;
            41 } elsif ( $path =~ m/^(\/.*)$/ ) {
            42 $dirs_check{"$1"} = "$flags";
            43 next;
            44 } else { print "unmatched $path\n";}
            45
            46 }
            47 close CONF;

            and gives me
            wrong format dd/dd
            unmatched =ho/ddd
            #####exlcuded
            /var/log/messages.*
            /mnt/extra/system_backup/etc/reoback
            #####match only
            /bar My
            /foo r+r
            #####search only
            /mnt/extra/system_backup/etc t+t+t
            /mnt Myrule
            /goo/goo r+t

            Pavlos


            --
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            I love having the feeling of being in control
            while i have the sensation of speed

            The surfer of life
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            GnuPG Key: FB1E6AE7
            Fingerprint A9AE EA0C EE1F FBD0 5B6F 3F77 2782 EFE2 FB1E 6AE7
            Get my key here: http://users.hol.gr/~p_pavlos/pubpgpkey.txt
          • satish
            Dear Sir, Can anyone suggest me how to write pattern matching for ph*.jpg, displaying all the jpg files starting from ph. Thanks and regards, Satish KM
            Message 5 of 25 , Dec 7, 2005
            • 0 Attachment
              Dear Sir,

              Can anyone suggest me how to write pattern matching
              for ph*.jpg, displaying all the jpg files starting
              from ph.

              Thanks and regards,
              Satish KM



              __________________________________________________
              Do You Yahoo!?
              Tired of spam? Yahoo! Mail has the best spam protection around
              http://mail.yahoo.com
            • Prakash Kumar
              /^ph.* .jpg$/i -Prak
              Message 6 of 25 , Dec 7, 2005
              • 0 Attachment
                /^ph.*\.jpg$/i

                -Prak


                On Wed, 7 Dec 2005, satish wrote:

                >
                >
                >
                > Dear Sir,
                >
                > Can anyone suggest me how to write pattern matching
                > for ph*.jpg, displaying all the jpg files starting
                > from ph.
                >
                > Thanks and regards,
                > Satish KM
                >
                >
                >
                > __________________________________________________
                > Do You Yahoo!?
                > Tired of spam? Yahoo! Mail has the best spam protection around
                > http://mail.yahoo.com
                >
                >
                >
                > Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html
                > Yahoo! Groups Links
                >
                >
                >
                >
                >
                >
                >
              • srinivas reddy
                I think this would work: /^ph.* .jpg$/ Thanks, Srinivas. ... -- Best Regards, Srinivas Reddy...... [Non-text portions of this message have been removed]
                Message 7 of 25 , Dec 7, 2005
                • 0 Attachment
                  I think this would work:

                  /^ph.*\.jpg$/


                  Thanks,
                  Srinivas.

                  On 12/8/05, satish <satyakm79@...> wrote:
                  >
                  >
                  >
                  >
                  > Dear Sir,
                  >
                  > Can anyone suggest me how to write pattern matching
                  > for ph*.jpg, displaying all the jpg files starting
                  > from ph.
                  >
                  > Thanks and regards,
                  > Satish KM
                  >
                  >
                  >
                  > __________________________________________________
                  > Do You Yahoo!?
                  > Tired of spam? Yahoo! Mail has the best spam protection around
                  > http://mail.yahoo.com
                  >
                  >
                  >
                  > Unsubscribing info is here:
                  > http://help.yahoo.com/help/us/groups/groups-32.html
                  > Yahoo! Groups Links
                  >
                  >
                  >
                  >
                  >
                  >
                  >
                  >


                  --
                  Best Regards,
                  Srinivas Reddy......


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