in reply to Reg Ex with quotes

Your problem is that you have used a char set where you intended a capture. The fixed (and simplified) regex looks like /("[^"]*")/.

use strict; use warnings; my @test; while (my $line = <DATA>) { if ($line =~ /("[^"]*")/) { my $keep = $1; push(@test,$keep); } } (print join "\n", @test) if @test; __DATA__ rmdir: directory "SAS_util0001000021A9_sasux101": Directory rmdir: directory "SAS_util000100002E19_sasux101": Directory rmdir: directory "SAS_util000100005891_sasux101": Directory

Prints:

"SAS_util0001000021A9_sasux101" "SAS_util000100002E19_sasux101" "SAS_util000100005891_sasux101"

DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: Reg Ex with quotes
by duckyd (Hermit) on Jan 30, 2006 at 23:56 UTC
    /"([^"]*)"/
    is probably even better, unless you really do want the quotes captured too. The value of the capture will be available in $1.

      That is what I would do, but doesn't match the inferred intent of OP's code. (Mind you, my version doesn't do the checking that the original code did either. :) )


      DWIM is Perl's answer to Gödel
Re^2: Reg Ex with quotes
by Anonymous Monk on Jan 30, 2006 at 23:59 UTC
    Looks great but I get a compilation error with the reg ex.. Thanks Joe..