matching alphanumeric string

how to match an alphanumeric string like the following.

i have to do like the following.

if the input line is

the data is {clock_91b}

i have to replace that with

the string was ("clock_91b")

i tried like

$line =~ s/the data is\s+\{([a-z]+)\}/the string was \(\"$1\"\)/

which is not working.
Is there any idea?
:slight_smile:

Well, sounds like homework to me, but looks like you have already put in the effort, and close to a solution, so I will reply (and chastise me if I shouldn't have, guys).

My solution does not use $1 (I need a little sed research myself), but instead uses \1 to back-reference the 1st parenthesized expression:

echo 'your input line' |
sed "s/the data is {\(.*\)}/the string was \(\"\1\"\)/"

and I did not have to escape the braces with backslashes.

Jimbo

thanks jimbo, i could do that like this

$line =~ s/the data is {(.*)}/the string was \(\"$1\"\)/;

sorry for the confusion, since this is a model of the actual problem i faced. I could not give my company data directly here which would have been a solution for your doubt!

But sometimes it does not hear good to listen such comments when somebody tends to ask a question after a hectic session of trial in the office along with the tensions to finish the things within the last quarter of the year!!

well, thanks anyway.
:slight_smile:

My apologies, sskb. I am fairly new to this forum, and I will get better at spotting homework as opposed to someone trying to get their job done. I want to help (and learn in the process of helping), and follow the forum rules in the process.

I hope your year-end goes well, and Happy Holidays.

thanks Jimbo for your understanding.
well, I am sorry if I have hurt you!!
wish you a happy christmas!
:slight_smile: :slight_smile: