Skip to content

Instantly share code, notes, and snippets.

@suchipi
Created October 6, 2015 04:19
Show Gist options
  • Save suchipi/4f94e96faab1615965d7 to your computer and use it in GitHub Desktop.
Save suchipi/4f94e96faab1615965d7 to your computer and use it in GitHub Desktop.
@RegexHelpers =
# matches colors like #ffffff, #eee, rgb(255,255,255), and rgba(255, 255, 255, 0.25)
cssColorMatchString: '(?:#(?:[0-9a-f]{6}|[0-9a-f]{3}))|(?:rgba?\\((?:\\d+, *){2,3}(?:\\d+(?:\\.\\d+)?)\\))'
makeTagRegex: (tagName, attributeMatch=".*") ->
# matches:
# <tagName attribute>content</tagName>
# [tagName: attribute]content[/tagName]
# <tagName = attribute>content</tagName>
# <tagName>content</tagName>
#
# $1 is attribute, $2 is content
attributeMatch = attributeMatch.join('|') if _.isArray(attributeMatch)
new RegExp "(?:<|\\[)#{tagName}(?: *(?: |:|=) *(#{attributeMatch}))? *(?:>|\\])(.+)(?:<|\\[)\\/#{tagName}(?:>|\\])", 'ig'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment