I'm just starting to learn Perl. I need to parse JavaScript file. I came up with the following subroutine, to do it:
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 the string:
s/[\'\;]//g;
It works alright but if there is a mentioned chars ('
and ;
) in string - then they are also removed. This is undesirable and that's where I stuck as it gets a bit more complicated for me and I'm not sure how to change the regex above correctly to only:
- Remove only first
'
in string - Remove only last
'
in string - Remove ont last
;
in string if exists
Any help, please?