in reply to Re: Is there a way I can substitute for ":" except when it is preceded by a letter C
in thread Is there a way I can substitute for ":" except when it is preceded by a letter C

But what if the string is ':foo'?

s/([^C:]*):/$1'/g;

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

  • Comment on Re: Re: Is there a way I can substitute for ":" except when it is preceded by a letter C
  • Download Code

Replies are listed 'Best First'.
Re: Re: Re: Is there a way I can substitute for ":" except when it is preceded by a letter C
by MrNobo1024 (Hermit) on Aug 17, 2002 at 02:35 UTC
    That's not quite right, the * makes it match even if there's 0 C's, turning all colons into apostrophes, not just the intended ones
    s/(^|[^C]):/$1'/g
    fixes that, but won't work if there is multiple colons in a row. A negative lookbehind is probably the only way to do this properly.

    --MrNobo1024
    s]]HrLfbfe|EbBibmv]e|s}w}ciZx^RYhL}e^print