[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

regex replace on a file

eggie5

10/23/2007 7:45:00 AM

I want to do a simple regex replace on a file. I want to replace this
multiline match

<!--scripts-->[\\S\\s]*?<!--endscripts-->

with this string:

<script type="text/javascript" src="/path/to/javascript.js"></script>

How can I do this with ruby assuming my file is: /html/page.html

2 Answers

Robert Klemme

10/23/2007 8:26:00 AM

0

2007/10/23, eggie5 <eggie5@gmail.com>:
> I want to do a simple regex replace on a file. I want to replace this
> multiline match
>
> <!--scripts-->[\\S\\s]*?<!--endscripts-->
>
> with this string:
>
> <script type="text/javascript" src="/path/to/javascript.js"></script>
>
> How can I do this with ruby assuming my file is: /html/page.html

Please show us what you have already.

Kind regards

robert

Bertram Scharpf

10/23/2007 11:35:00 AM

0

Hi,

Am Dienstag, 23. Okt 2007, 16:50:04 +0900 schrieb eggie5:
> I want to do a simple regex replace on a file. I want to replace this
> multiline match

As far as I see for multilines the -i option doesn't work.
You could do something like

whole = File.read "fname"
whole.gsub! /.../m, "..."
File.open "fname.mod" do |f| f.write whole end

Sorry, but I suppose the best tool for this task is Vim.

Bertram


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-...