Skip to content

Instantly share code, notes, and snippets.

@sanchojaf
Last active November 6, 2016 14:56
Show Gist options
  • Save sanchojaf/1075f86a57419a5e64cc573fb241b080 to your computer and use it in GitHub Desktop.
Save sanchojaf/1075f86a57419a5e64cc573fb241b080 to your computer and use it in GitHub Desktop.
Matching Keyword-Value Pair (ruby, regular expressions)
# Extracts the keyword and the value. The assumptions are that
# the keyword oor attribute is a single word, the value extends
# to the end of the line, and the equal sign may be surrounded
# by whitespace.
expression = /(\w+)\s*=\s*(.*?)$/
sample_text = "color = blue"
sample_text =~ expression
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment