in reply to Replace strings with "("

I'm not exactly clear what your objective is, i.e., what in the original string is to be replaced and what is to be preserved.

But assuming that an open paren is to be preserved, then you have to backslash it. Instead, in the regex shown you have backslashed a close paren. That's at least part of what is driving you crazy.

jimk

Replies are listed 'Best First'.
Re^2: Replace strings with "("
by chintak86 (Initiate) on Jan 30, 2005 at 00:13 UTC
    The objective is to replace the following string:

    test("test

    with test("GC_test

    i.e. put GC_ before the second "test". Hope that answers your query.

    As well backslashing the open paren didn't work. That was my initial solution. But I did try your suggestion but no luck.

    Please help; and thanks
      #!/usr/bin/perl -w use strict; my $str_in = 'test("test'; my $str_out = $str_in; #$str_out =~ s/"t/"GC_t/; $str_out =~ s/"/"GC_/; print "string 1: $str_in\n"; print "string 2: $str_out\n";

      produces

      string 1: test("test string 2: test("GC_test

      Am I missing something here?

      Update: Just match the double quote (original match commented out above). That works just well, assuming there is only one double quote in the string.