Skip to content
accelerando

Ampersands and XHTML

A regular expression to replace all ampersands (&) in a text that are not part of an entity:

t = t.gsub(/&(?!#?\w+;)/, '&')

Language is ruby. The regexp feature used is called a negative lookahead.

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*

*
Close
E-mail It