Ruby: Strip html tags from a string
str = "<html>This and <b>that</b> and <br />and <span class='something'>the other</span>?<html>" puts str.gsub(/<\/?[^>]*>/, "")
12111 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
str = "<html>This and <b>that</b> and <br />and <span class='something'>the other</span>?<html>" puts str.gsub(/<\/?[^>]*>/, "")
class String def count_words n = 0 scan(/\b\S+\b/) { n += 1} n end end
<div(?=\s) (?: (?!\sid=|>) . )* # Consume everything until finding " id=" or ">" # (">" is just for failing faster) \sdiv=(?P<__quote>['"])? # Consume " div=" and save the quote type (' or ") if any (?: # while (?! # next character isn't, (?(__quote) # if a quote has been opened, (?P=__quote) # the closing quote ; |[\s>] # a space or ">" else, ) ) . # consume this character )* (?(__quote) # If we got a quote (?P=__quote)| # it must be closed (?=[\s>]) # else, the attribute is ended by a space or ">" ) [^>]*> # Consume the rest of the tag
e = assert_raise(RuntimeError) { my_code_that_raises } assert_match(/Error message here/i, e.message)..
<div[^>]*>
<div>[^div]*</div>
<div> (?: (?!</div>) # If not followed by </div> . # Match any character )* # Non-capturing grouping </div>
s/([^\n]{0,80})\s/$1\n/mg
/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/
/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/
String noHTMLString = htmlString.replaceAll("\\<.*?\\>", "");
/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix
class Comment < ActiveRecord::Base validates_format_of :SiteURL, :with => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix, :on => :create end