gsub

Rails fails to return scripts/stylesheets

This only happens on my local machine (Windows 7, Ruby 1.8.7). Occasionally rails will just stop returning my stylesheets/javascript and I'll get gross looking pages. If I navigate directly to those scripts, sometimes they work, and sometimes I get errors like: private method `gsub!' called for #<Class:0x76ff830> What could be causing...

[Ruby on Rails] scribd_fu gsub error

I have an application which allow user upload documents to Scribd. I tried to use scribd_fu in Rails. An error occurred when the controller try to save the model. NoMethodError in DocumentsController#processupload private method `gsub' called for nil:NilClass here is the related controller def processupload @document = Document.new...

lua gsub %b <-- how does this work?

In the following lua code: function interp(s, tab) return (s:gsub('($%b{})', function(w) return tab[w:sub(3, -2)] or w end)) end what does the %b mean? and how does this match stuff like "${name}" ? ...

Ignoring a character along with word boundary in regex

I am using gsub in Ruby to make a word within text bold. I am using a word boundary so as to not make letters within other words bold, but am finding that this ignores words that have a quote after them. For example: text.gsub(/#{word}\b/i, "<b>#{word}</b>") text = "I said, 'look out below'" word = below In this case the word below...

Escaping '“' with regular double quotes using Ruby regex

I have text that has these fancy double quotes: '“' and I would like to replace them with regular double quotes using Ruby gsub and regex. Here's an example and what I have so far: sentence = 'This is a quote, “Hey guys!”' I couldn't figure out how to escape double quotes so I tried using 34.chr: sentence.gsub("“",34.chr). This get...

Regex for removing certain variable numeric values from some text

I want to substitute all 4 instances of the number 300 from the code below (which my website users will be pasting whenever they create a new blog post), with 470. <div> <object width="300" height="300"> <embed src="link-removed" width="300" height="300"></embed> </object> <p> <a href="another-link">link</a> </p> </div> ...

Ruby String::gsub! pausing unexpectedly

Hello Everyone! I am working on a VERY simple script to clean up a few hundred thousand small XML files. My current method is to iterate through the directory and (for each file) read the file, use String::gsub! to make all my changes (not sure if this is best) and then I write the new contents to the file. My code looks something like ...

Newbie to RegEx..

I have this sample string : &Lt;! [If Gte Mso 9]>&Lt;Xml> &Lt;Br /> &Lt;O:Office Document Settings> &Lt;Br /> &Lt;O:Allow Png/> &Lt;Br /> &Lt;/O:Off... And I would like to target specifically anything that begins in an "" and ends in a ">", and replace it with no-space "". Been using Rubular, but I'm having a tricky time learning ...

Using Ruby's gsub with a string containing "\0"

I'm having trouble using gsub correctly: Given this code: "replace me".gsub(/replace me/, "this \\0 is a test") The result is: "this replace me is a test" But what I am expecting is: "this \0 is a test" How do I use gsub to get the result I want? ...

How do I inject <br> into text entered through a textarea in rails?

I have a textarea form which takes a large block of text. In this text area, I do a carriage return to end the paragraph and another carriage return to separate the paragraphs. That text is in @contact_postalcard.message. However, I need to output into an HTML file. The HTML file has been loaded as a long string which contains 'Rep...

How to add trailing slash if needed with gsub

I'm trying to add trailing slash if needed: a = "/var/www" a.gsub... I dont know how to do it. ...

rails gsub question

Hi, How can i replace " " and "_" with "-" in my controller when creating a new post? I have the following form fields: title url content I want to execute the gsub on the url field. Thanks... ...

How to gsub an unicode 0083 with ruby ?

Hi Guys, I have loaded a string from a html.file, and I have writen it to a yaml file with the plugin ya2yaml: - title: 'What a wonderful day!' body: ... # main contents here and I will load the .yml file by YAML::parse_file method. but "\n" in the string will cause load problems, so I tried to gsub all "\n" to "", but the...