On 2007-04-10 21:17,
<> wrote:
> On Apr 10, 4:43 pm, 4i4ko Trevi4ko <4i4ko_trevi...@hui.de> wrote:
>> On Tue, 10 Apr 2007 15:41:25 -0500, J. Gleixner wrote:
>> > sk wrote:
>> >> I m trying to add a extra keyword on a specific word in a html
>> >> document In the following document I want to put "My" in front of
>> >> all the words"computer" excluding the id for the stylesheet and
>> >> name of image files.
>>
>> >> <html>
>> >> <head>
>> >> <title>hello</titile>
>> >> </head>
>> >> <body>
>> >> <div id="computer"> This is computer</div>
>> >> <img src="images/computer.jpg" >Computer
>> >> </body>
>> >> </html>
>>
>> > s/\scomputer/ My computer/;
>>
>> will not work on:
>> <img src="images/computer.jpg" >Computer
>
> I got it through 2 regular expressions. Maybe someone can help me
> merge them together...
>
> $string =~ s/(>.*)(computer)(.*<)/\1my \2\3/igms;
That will match
$1: From the first ">" to the ">" in the img tag in line 7.
$2: "Computer" in line 7
$3: From the newline after "Computer" to the opening "<" in
"</html".
In other words it will only replace the last "Computer" in the file.
The "g" is ineffective, since there can be only one last "computer".
The "m" doesn't seem to have any effect either.
> $string =~ s/(>.*)(computer)(.*<)/\1my \2\3/ig;
This will replace any "computer" after a ">" and before a "<" on the
same line. In the example file there is only one "computer" left which
matches that criterion, but that doesn't seem guaranteed.
hp
--
_ | Peter J. Holzer | I know I'd be respectful of a pirate
|_|_) | Sysadmin WSR | with an emu on his shoulder.
| | |
|
__/ |
http://www.hjp.at/ | -- Sam in "Freefall"