4 ms·
I have problems with linux and escape characters. grep '".*\?"' test.txt "test1" test2 "test3" matches entire string while article says that ? should force i
by shultays 13y ago
I have problems with linux and escape characters.
grep '".*\?"' test.txt
"test1" test2 "test3"
matches entire string while article says that ? should force it to match as little as possible. (All "test1", test2 and "test3" are highlighted as red) It works correctly http://regexpal.com/ http://regexpal.com/. What am I doing wrong?
- clarry 13y agoThis is when you learn that not all implementations are the same, and realize it's better to read the documentation for your particular implementation. I'm guessing your grep defaults to POSIX EREs, but always check the manual. The behavior of multiple adjacent duplication symbols ( '+', '*', '?', and intervals) produces undefined results. http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_...
- tbrownaw 13y agoYou don't need the \ (because it's in single quotes), and as mentioned by clarry all regex implementations are slightly different. grep '"[^"]*"' test.txt should be about the same, and not reliant on less-standard features.