Removing quotes from string

All you forgot was parens for the LHS to put the match into list context so it returns the submatch group(s). The normal way to do this is:

 ($expected_start_time) = $condition =~ /"([^"]*)"/;

It appears that you know that the first and last character are quotes. If that is the case, use

$expected_start_time = substr $conditions, 1, -1;

No need for a regexp.


The brute force way is:

$expected_start_time = $conditions;
$expected_start_time =~ s/"//g;

Note that the original regex:

m/(\"[^\"])/

would capture the opening quote and the following non-quote character. To capture the non-quote characters between double quotes, you'd need some variant on:

m/"([^"]*)"/;

This being Perl (and regexes), TMTOWTDI - There's More Than One Way Do It.

Tags:

String

Perl