Timeline for grep -w matches only the first occurrence of a pattern in a line
Current License: CC BY-SA 4.0
Post Revisions
12 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Mar 4, 2022 at 13:53 | answer | added | ilkkachu | timeline score: 2 | |
| Mar 3, 2022 at 21:49 | comment | added | ilkkachu | @aviro, It says it looks for "matches that form whole words". And ok, fine, if the man page says it accepts non-word characters, then it does. But it doesn't make any sense that a "whole word" could contain "non-word characters". | |
| Mar 3, 2022 at 17:41 | history | edited | aviro | CC BY-SA 4.0 |
added 395 characters in body
|
| Mar 3, 2022 at 17:37 | comment | added | Stephen Kitt |
And the info page specifically mentions that non-word characters are allowed: “Because the -w option can match a substring that does not begin and end with word constituents, it differs from surrounding a regular expression with ‘\<’ and ‘\>’.”
|
|
| Mar 3, 2022 at 17:37 | history | edited | aviro | CC BY-SA 4.0 |
added 395 characters in body
|
| Mar 3, 2022 at 17:25 | comment | added | aviro |
@ilkkachu, the -w, --word-regexp section in the man pages of grep doesn't require that the substring must be comprised of word characters. It says nothing about the pattern itself. It only states what it should be preceded and followed with. So you can match a string that contains non-word characters, as long as it's preceded and followed with non-word characters (or beginning/end of the line).
|
|
| Mar 3, 2022 at 16:23 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 |
clarifaction as to what implementation of grep we're talking about (from comments)
|
| Mar 3, 2022 at 15:57 | comment | added | ilkkachu |
Mmhh. Since = isn't a word-constituent character, I'm not sure how much sense it makes to have a pattern that can accept trailing =s while at the same time looking for whole word matches. I mean, if it's supposed to match a "word", the matching string would probably need to be such that it only contains characters valid in a "word".
|
|
| Mar 3, 2022 at 14:49 | comment | added | pLumo | I see ... yes .. sorry, I guess you're right.... | |
| Mar 3, 2022 at 14:17 | answer | added | pLumo | timeline score: 3 | |
| Mar 3, 2022 at 13:58 | comment | added | pLumo |
Your grep -owP example output is different from mine (mine is as I would expect)
|
|
| Mar 3, 2022 at 13:36 | history | asked | aviro | CC BY-SA 4.0 |