in reply to Re: strip text from a string
in thread strip text from a string

s/(\s*'[^']*?')//g;

I'm not sure why you enclose the pattern in parentheses as I don't think a capture is required. Also, you don't need the non-greedy quantifier when using negated character classes, that's the whole point of using them as it means you can avoid the commonly seen .*? pattern.

I hope this is of interest.

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^3: strip text from a string
by Athanasius (Archbishop) on Sep 11, 2014 at 15:45 UTC

    Hello johngg,

    Both excellent points! Thanks for the corrections:

    1:41 >perl -wE "my $s= qq[Can you please remove 'me' as that me is no + longer required, but this 'X' should go as well]; $s =~ s/\s*'[^']*' +//g; say qq[\n$s];" Can you please remove as that me is no longer required, but this shoul +d go as well 1:41 >

    Cheers,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Re^3: strip text from a string
by KalaMonkey (Initiate) on Sep 11, 2014 at 15:31 UTC
    That did the trick thanks!