Menu

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

Accepted
nobody
None
Medium
Defect
2012-06-06
2012-02-17
Anonymous
No

Originally created by: dgryski

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.

1 Attachments

Discussion

  • Anonymous

    Anonymous - 2012-02-23

    Originally posted by: dgryski

    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.

     
  • Anonymous

    Anonymous - 2012-06-06

    Originally posted by: dgryski

    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.

    Status: Accepted

     

Log in to post a comment.

MongoDB Logo MongoDB