Skip to content
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

Support grep's "-w" flag [PATCH] #13

Open
GoogleCodeExporter opened this issue Mar 24, 2015 · 2 comments
Open

Support grep's "-w" flag [PATCH] #13

GoogleCodeExporter opened this issue Mar 24, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

It's nice to be able to search for 'whole words', which is to say making sure 
the pattern has a word boundary at the beginning and end.

Having to type '\bpattern\b' is annoying, and grep/ack already have a -w flag 
which does this for you.
Since we already have -i which adjusts the pattern, I think adding another one 
isn't to terrible.

I've attached a patch that does this.

Original issue reported on code.google.com by dgryski on 17 Feb 2012 at 1:13

Attachments:

@GoogleCodeExporter
Copy link
Author

Blindly adding \b to the start and end of the pattern fails for cases where the 
pattern _already_ starts or ends on a word-boundary.

I've updated the patch with a better fix.  I've copied the implementation of 
regex.isWordByte() because we need to know what regex thinks is a word 
boundary.  An alternate fix would be to export this function directly from the 
package.

Original comment by dgryski on 23 Feb 2012 at 9:10

Attachments:

@GoogleCodeExporter
Copy link
Author

This patch only works for trivial cases, and making it work in the full case is 
Hard(er).

Full discussion on the patch set:

https://codereview.appspot.com/6162045/

I'm leaving this open for now, because it's still a nice feature.

Original comment by dgryski on 6 Jun 2012 at 8:10

  • Changed state: Accepted

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

No branches or pull requests

1 participant