in reply to Re: A text replacement question
in thread A text replacement question

well the 'names' i mentioned arent links - theyre names for values that get recorded. The code for the checkboxes is like
(code value=1 name =xvx) (code value=2 name= xvx)... and so on for each checkbox. So the idea is for the code to get any ? v ? and replace it with itself embedded in the code - saving me 500 years of time! Thanks for the help - much aprreciated! (steamerboy)

Replies are listed 'Best First'.
Re^3: A text replacement question
by Animator (Hermit) on Feb 15, 2005 at 14:37 UTC
    It would be much easier if you gave real examples of the input and the expected output...
      Looking at one of the files you would see would see;

      AAvIY
      AAvT
      AAvY
      AAvHH
      TvHH
      ZHvTH
      DHvZH

      ...
      and many, many more!
      And what im expecting as output is

      (for 13v13 - im using letters in my code though!)
      <INPUT TYPE=radio NAME=13v13 VALUE='' CHECKED>three & six
      weak<INPUT TYPE=radio NAME=13v13 VALUE=1><INPUT TYPE=radio NAME=13v13 VALUE=2><INPUT TYPE=radio NAME=13v13 VALUE=3><INPUT TYPE=radio NAME=13v13 VALUE=4><INPUT TYPE=radio NAME=13v13 VALUE=5><INPUT TYPE=radio NAME=13v13 VALUE=6><INPUT TYPE=radio NAME=13v13 VALUE=7>strong


      so for AAvBB i'd want to get; weak<INPUT TYPE=radio NAME=AAvBB VALUE=1> <INPUT TYPE= radio NAME=AAvBB VALUE=2>....<INPUT TYPE radio NAME=AAvBB VALUE=5>strong


      . ideally id like the regex to operate on xvx but not NAME=xvx. Hope that helps

        That sure helps.

        You can do this via a one-liner or via real code.

        (untested one-liner):

        perl -pi.bak -e 's/(?!<NAME)(\w{2}v\w{2})/&replace($1)/ieg; BEGIN { sub replace { my $name = shift; return "<input type=..... name=$name>...."; } }' *.html

        All you need to do now, is modify the replace subroutine.