Skip to content

Instantly share code, notes, and snippets.

@marugoshi
Created May 14, 2010 18:48
Show Gist options
  • Select an option

  • Save marugoshi/401485 to your computer and use it in GitHub Desktop.

Select an option

Save marugoshi/401485 to your computer and use it in GitHub Desktop.
module Ext
module String
def self.included(base)
base.class_eval do
include InstanceMethods
end
end
module InstanceMethods
def br_to_return
self.gsub(/<(BR|br|BR \/|br \/)>/, "\n")
end
def br_to_return!
self.gsub!(/<(BR|br|BR \/|br \/)>/, "\n")
end
def return_to_br
self.gsub(/\r\n/, "\n").gsub(/\r/, "\n").gsub(/\n/, "<br />")
end
def return_to_br!
self.gsub!(/\r\n/, "\n")
self.gsub!(/\r/, "\n")
self.gsub!(/\n/, "<br />")
end
def strip_html_tag
self.gsub(/<[^<>]*>/,"") while /<[^<>]*>/ =~ self
end
def strip_html_tag!
self.gsub!(/<[^<>]*>/,"") while /<[^<>]*>/ =~ self
end
def strip_return
self.gsub(/\r\n/, "\n").gsub(/\r/, "\n").gsub(/\n/, "")
end
def strip_return!
self.gsub!(/\r\n/, "\n")
self.gsub!(/\r/, "\n")
self.gsub!(/\n/, "")
end
end
end
end
String.send :include, Ext::String
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment