If a group is defined in the regexp, only highlight/copy this group
Opened this issue · 3 comments
This way we can choose to only copy part of the match. Sometimes we provide context for matching but don't want to copy it (and it seems like lookahead and lookback aren't supported).
A less intrusive option is if there is a specific named group then only highlight/copy that.
I agree this would be very nice and it would enable some nice things we can't have because these other features are missing.
If this can be implemented in a non-complex way, I'd be very open to accepting a PR.
I made a slight change to use perl regex (-P) instead of Extended regex (-E)
# (tac 2>/dev/null || tail -r) < "$file" | grep -oniE "$grep_pattern" > "$copycat_file"
(tac 2>/dev/null || tail -r) < "$file" | grep -oniP "$grep_pattern" > "$copycat_file"
This allowed me to to some lookahead/lookback in my .tmux.conf
Match everything on a line following prompt> but do not include prompt>
set -g @copycat_search_C-i '(?<=prompt> ).*'
Match object names between { } but do not include { }
set -g @copycat_search_C-o "(?<={)[a-zA-Z0-9_/.-]+(?=})"
Details on the Perl Look Ahead Assertions that I used (?<=) and (?=) are here:
http://perldoc.perl.org/perlre.html#Extended-Patterns
Hey, that's nice.
Just keep in mind grep -P
flag is not part of posix definition. For example, it wouldn't work on OSX.