saldoman has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on regular expression to retrieve text within single quotes

Replies are listed 'Best First'.
Re: regular expression to retrieve text within single quotes
by rinceWind (Monsignor) on May 11, 2005 at 12:12 UTC
    /'([^']+)'/

    should do the trick.

    --
    I'm Not Just Another Perl Hacker

Re: regular expression to retrieve text within single quotes
by gellyfish (Monsignor) on May 11, 2005 at 12:09 UTC

    I think you are missing something from your description of the problem but if one is to take you at your word then something like:

    my $foo = "'stuff in quotes'"; $foo =~ /'(.*)'/ and $foo = $1; print $foo;
    should suffice.

    /J\

Re: regular expression to retrieve text within single quotes
by tlm (Prior) on May 11, 2005 at 12:16 UTC

    I would vote for

    /'(.*?)'/
    or maybe even
    /'(.*?)'/s
    in case the quoted text includes newlines.

    the lowliest monk

Re: regular expression to retrieve text within single quotes
by thcsoft (Monk) on May 11, 2005 at 12:35 UTC
    lol... :)
    so, here's yet another one:
    my $newstring = ''; while ($string =~ /(\'|\")(.*?)\1/) { $newstring .= $2; }
    language is a virus from outer space.
Re: regular expression to retrieve text within single quotes
by ikegami (Patriarch) on May 11, 2005 at 14:14 UTC
    It's not a regexp, but $str = substr($str, 1, -1) does the trick efficiently, assuming the quotes are guaranteed to be there.