Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to delete single quotes but not apostrophes in perl

Tags:

perl

I would like to know how to delete single quotes but not apostrophes in perl.

For example:

'It's raining again!'

print

It's raining again!

Thanks so much

like image 412
user1896162 Avatar asked Dec 11 '12 23:12

user1896162


1 Answers

If you assume that a single-quote is always preceded or followed by whitespace, the following pair of regular expressions should work:

$line =~ s/\s'/ /g;  #preceded by whitespace
$line =~ s/'\s/ /g;  #followed by whitespace

you also need to account for if the string starts or ends with a single quote:

$str =~ s/^'//;  #at the start of a string
$str =~ s/'$//;  #at the end of a string
like image 198
Tim A Avatar answered Nov 07 '22 12:11

Tim A