For a ruby on rails assignment I am supposed to block anyone with the name Pat. I do not want to black names such as Patrick though.
Right now I have
validates :author, :format => {:without => /pat/i}
The above validations will of course also block names such as Patrick
I have tried the regular expression below and it didn’t catch Pat unless there was a space or something else that is not a character.
/pat\W/i
I am unsure how to make it so it only catches a name that contains Pat but not a name with a Pat in it such as Patrick. Any help will be appreciated.
Use word boundaries:
/\bpat\b/i