0

I just want to remove double quotes(") of a string "dropDownStorePrepare(this,\'hello\')". Tried this way but not working.

#!/usr/bin/perl
use strict;
use warnings;
my $str = '"store":"dropDownStorePrepare(this,\'hello\')","name":"Rama Rao"';

$str =~ s/"dropDownStorePrepare(.*)"/dropDownStorePrepare$1/ig;

print $str;

Double quotes which are at the beginning and ending of the dropDownStorePrepare(,,,) should be removed and rest of the double quotes should be remained.

Note: dropDownStorePrepare function should accept any no of parameters.

Can somebody help me please..

2 Answers 2

3

The immediate problem you've got is that the .* is matching too much. Try:

$str =~ s/"dropDownStorePrepare(.*?)"/dropDownStorePrepare$1/ig;

Though it looks like you're trying to parse JSON. Maybe you should look for a module to do that for you…

Sign up to request clarification or add additional context in comments.

Comments

2

Try non greedy regex,

$str =~ s/"dropDownStorePrepare(.*?)"/dropDownStorePrepare$1/ig;

3 Comments

@RamaRaoM you can shorten right side by capturing everything inside $1, _______________________ $str =~ s/"(dropDownStorePrepare.*?)"/$1/ig;
@mpapec But that won't do case normalization. (That might or might not be wanted.)
@DonalFellows yes, but it is also hard to tell whether normalization was intentional or accidental (I would say accidental judging from input string).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.