All posts tagged with 'regular expressions'

Ampersands and XHTML

25-May-08

A regular expression to replace all ampersands (&) in a text that are not part of an entity: t = t.gsub(/&(?!#?\w+;)/, ‘&’)t = t.gsub(/&(?!#?\w+;)/, ‘&’) Language is ruby. The regexp feature used is called a negative lookahead.

Read the complete article »

Don’t make that sad smilie cry even more

22-Aug-07

Escaping single quotes in ruby is the same mess as in java: puts ":'(".gsub(’\”, ‘\\\\\”)puts ":'(".gsub(‘\”, ‘\\\\\”) I needed this to make the smilies after my comment box (here) clickable. Shortly after that, i found escape_javascript, maybe it still comes in handy.

Read the complete article »