Created
September 18, 2010 08:17
-
-
Save hhatto/585479 to your computer and use it in GitHub Desktop.
patch of grin force word regex match
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: grin.py | |
=================================================================== | |
--- grin.py (revision 80) | |
+++ grin.py (working copy) | |
@@ -762,6 +762,8 @@ | |
help="show program's version number and exit") | |
parser.add_argument('-i', '--ignore-case', action='append_const', | |
dest='re_flags', const=re.I, default=[], help="ignore case in the regex") | |
+ parser.add_argument('-w', '--word-regexp', action='store_true', default=False, | |
+ dest='is_matchword', help="force regex to match only whole words") | |
parser.add_argument('-A', '--after-context', default=0, type=int, | |
help="the number of lines of context to show after the match [default=%(default)r]") | |
parser.add_argument('-B', '--before-context', default=0, type=int, | |
@@ -1003,7 +1005,11 @@ | |
flags = 0 | |
for flag in args.re_flags: | |
flags |= flag | |
- return re.compile(args.regex, flags) | |
+ if args.is_matchword: | |
+ regex = "\\b(%s)\\b" % args.regex | |
+ else: | |
+ regex = args.regex | |
+ return re.compile(regex, flags) | |
def grin_main(argv=None): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment