in reply to Re: Replacing characters in a line
in thread Replacing characters in a line

Why not just s/(?<=TYR )D/X/;?

Update:
Or, to keep it fixed-length:
s/^(.{21})D/$1X/;

Sidenote:
Has anyone an idea, why this:
s/^(?<=.{21})D/X/;
does not work, while this
s/(?<=.{21})D/X/;
does (but donīt use this, itīs unsafe)?


holli, /regexed monk/

Replies are listed 'Best First'.
Re^3: Replacing characters in a line
by manav (Scribe) on Mar 04, 2005 at 13:19 UTC
    Are we sure that D will always be preceeded by "TYR " ??
    Manav
      We can only tell from the example data.
      pelagic's regex is also unsafe. what if the line looks like
      ATOM 3316 N TYR B 24 97.479 18.805 2.990 1.00 36.32 + D N
      Then the alone "D" at the end will be replaced by "X". Intended??


      I would use the substr()-solution above. My regex was just meant as an optimization of perlsen's one, which is unneccesary complicated.

      Update:
      Striked the sillyness about the second "D".
      /me writes "Must read the question properly" 200 times.


      holli, /regexed monk/
      We are not!
      As the OP stated: there are two D's on every line.

      pelagic