Skip to content

bug in Regexp in Chapter 4 #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
aidancully opened this issue Nov 30, 2010 · 0 comments
Open

bug in Regexp in Chapter 4 #8

aidancully opened this issue Nov 30, 2010 · 0 comments

Comments

@aidancully
Copy link

Chapter 4 / Regular Expressions / Don't Work Too Hard introduces the section with the following code:

["James Gray", "James gray", "james gray", "james Gray"].all? { |e| ?> e.match(/James|james Gray|gray/) }

The regex in this example (/James|james Gray|gray/) will match any string containing "James", or "james Gray", or "gray", which is probably not what you intended. That is,

>> "gray".match(/James|james Gray|gray/) && true
=> true
>> "Gray".match(/James|james Gray|gray/) && true
=> nil

Suggest either /(James|james) (Gray|gray)/ or /(?:James|james) (?:Gray|gray), or note that finding the bug is an exercise for the reader.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant