Skip to content

Why is word match not working? #2775

Answered by BurntSushi
rew1nter asked this question in Q&A
Discussion options

You must be logged in to vote

This has nothing to do with the --w/--word-regexp flag. This is due to the fact that grep uses basic regular expressions (BREs) by default. BREs have different escaping rules and different rules around when * is "special" or not. In this case, since it appears the beginning of the regex, it isn't "special" and matched literally. If you use extended regular expressions (EREs) instead, then the * is treated specially:

$ wmctrl -d | grep -E '*'
grep: warning: * at start of expression
0  - DG: 2560x1600  VP: N/A  WA: N/A  1
1  - DG: 2560x1600  VP: N/A  WA: N/A  2
2  - DG: 2560x1600  VP: N/A  WA: N/A  3
3  - DG: 2560x1600  VP: N/A  WA: N/A  4
4  * DG: 2560x1600  VP: N/A  WA: N/A  mail
5  - DG:…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by BurntSushi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants