Updated regex pattern for countNouns() function