for `word = "isogram" result = word.match(/(.)\1|\d/i) p !result` how to change so that hyphenated words are also processed? in ruby

To include hyphenated words in the regex pattern, you can modify it as follows:

main.rb
word = "iso-gram"
result = word.match(/(.)(?:\1|-|\d)/i)
p !result
67 chars
4 lines

In this updated pattern, (.) matches any character except a newline and captures it. (?:\1|-|\d) is a non-capturing group that matches either the captured character (\1), a hyphen -, or a digit \d.

So, with the modified regex pattern, the resulting match will include hyphenated words as well.

related categories

gistlibby LogSnag