in reply to grep : partial and/or exact match

Ok that works fine for exact matches, but what if the word is funkhead or crudshorts?

What do you want to do with "funkhead" or "crudshorts"? Think carefully. If you want to reject them based on your list of restricted words, you're going to get a lot of false positives based on legitimate words like "crude". (The same happens when you substitute "real" dirty words.)

If you don't want a false positive, you'll find that \b is your friend. See perlman:perlre.

Replies are listed 'Best First'.
Re^2: grep : partial and/or exact match
by Sidd@786 (Initiate) on Jun 17, 2020 at 05:51 UTC

    how this partial mismatching is done in this scenario. file1 contents: he/is/man/reg30 don't/you/reg31 what/goes/on/reg32 file2 contents: /is/man/reg30 on/reg32 try/to/do/reg65 output should be: don't/you/reg31

        my $file1 = \<<"END1"; he/is/man/reg[30] what/goes/on/reg[32] i_am_a_man you_are_reg[60] END1 my $file2 = \<<"END2"; /is/man/reg[30] are_reg[60] try/to/do/reg[65] you/reg[31] END2 open(my $f3, ">", "C:/Users/Siddharth/Desktop/two.txt") or die "Can't open < input.txt: $!"; open my $h2, '<', $file2 or die "cannot open file2"; my %map = <$h2>; my ($regex) = map { qr/$_/ } # 2. join '|', map {quotemeta} close $h2; open my $h1, '<', $file1 or die "cannot open file1"; my @a1= <$h1>; #print grep {$_ =~ $regex} @a1; print $f3 grep {$_ !~ $regex} @a1;

        2020-06-21 Athanasius added code tags.