To modify the regex /(.).*\1|\d/i
to also check for hyphens and white spaces, you can update it as /(.).*\1|\d|[-\s]/i
.
In this updated regex pattern:
[-\s]
matches any hyphen (-
) or white space (\s
).Here's an example usage in Ruby:
main.rb170 chars9 lines
This code will output "String matches the pattern" because the given string contains a character repeated, a digit, and a hyphen.
Note that the i
at the end of the regex pattern (/i
) makes the matching case-insensitive.
Remember to enclose the regex pattern within /.../
and use the match?
method to check if the pattern matches the given string in Ruby.
gistlibby LogSnag