Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@KamilaBorowska
Created December 9, 2012 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KamilaBorowska/4244090 to your computer and use it in GitHub Desktop.
Save KamilaBorowska/4244090 to your computer and use it in GitHub Desktop.
function to_regex(array, regex, property, value) {
regex = ""
for (property in array) {
value = array[property]
gsub(/\W/, "\\\\&", value)
regex = regex value "|"
}
return "(" substr(regex, 1, length(regex) - 1) ")"
}
BEGIN {
words[1] = "a"
words[2] = "an"
words[3] = "table"
words[4] = "table?"
regex = to_regex(words)
print regex
string = "Is an apple lying on a table?"
gsub(regex, "<&>", string)
print string
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment