Created
December 9, 2012 09:56
-
-
Save KamilaBorowska/4244090 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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