I'm just starting to learn Perl. I need to parse a JavaScript file. I came up with the following routine:
sub __settings {
my ($_s) = @_;
my $f = $config_directory . "/authentic-theme/settings.js";
if ( -r $f ) {
for (
split(
'\n',
$s = do {
local $/ = undef;
open my $fh, "<", $f;
<$fh>;
}
)
)
{
if ( index( $_, '//' ) == -1
&& ( my @m = $_ =~ /(?:$_s\s*=\s*(.*))/g ) )
{
my $m = join( '\n', @m );
$m =~ s/[\'\;]//g;
return $m;
}
}
}
}
I have the following regex that removes 'and ;from a string:
s/[\'\;]//g;
This works well, but if the string contains the mentioned characters ( 'and ;), then they are also deleted. This is undesirable and that I am stuck as it becomes a little more difficult for me and I'm not sure how to change the regular expression correctly:
- Delete only the first
'in a row - Delete only the last
'in a row - Delete ont last
;in line if exists
Any help please?