Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! harrisjl's Avatar
    Join Date
    Aug 2012
    Location
    Raleigh, NC
    Posts
    8

    Perl/RegEx question


    I'm new to RegEx... I have a perl script that searches for worldwritable files and emails a list of them... There is an exception file where I store files and directories not to include in the email... It's working except for the following dir -> /lost+found...

    my $str1 = "/edi/qmway/archive/lost+found";
    my $str2 = "/lost+found";

    if ( $str1 =~ /$str2/ ) {
    print "true\n";
    }
    else {
    print "false\n";
    }

    my $str2 = "/lost+"; #returns true
    my $str2 = "/lost+found"; #returns false

    I know this is a newbie ? but how do I tell it to continue past the '+' sign and any other char? I think .* would match anything but a new-line but I'm screwing the syntax up THX

  2. #2
    Just Joined! harrisjl's Avatar
    Join Date
    Aug 2012
    Location
    Raleigh, NC
    Posts
    8
    my $str2 = "/lost/+found";

    I know I can escape it. But the text is coming from a line in a file and I don't want to have to hard code escape chars everywhere throughout the file ??

  3. #3
    Just Joined! harrisjl's Avatar
    Join Date
    Aug 2012
    Location
    Raleigh, NC
    Posts
    8
    This appears to work -> if ( $str1 =~ /\Q$str2\E/ ) {

    still testing scenarios....

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined! harrisjl's Avatar
    Join Date
    Aug 2012
    Location
    Raleigh, NC
    Posts
    8
    The quotemeta() function could be used for this as well

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •