regex replace on a file

E

eggie5

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
 
R

Robert Klemme

2007/10/23 said:
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
 
B

Bertram Scharpf

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,813
Messages
2,569,699
Members
45,489
Latest member
SwethaJ

Latest Threads

Top