Timeline for answer to Why do I have to quote an escaped character in a regular expression for grep, but not on online regex engines? by Olivier Dulac
Current License: CC BY-SA 4.0
Post Revisions
12 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jun 15, 2020 at 15:56 | vote | accept | dbates | ||
| S May 6, 2020 at 11:46 | history | suggested | Rolf | CC BY-SA 4.0 |
Fixed a typo.
|
| May 6, 2020 at 11:09 | review | Suggested edits | |||
| S May 6, 2020 at 11:46 | |||||
| Apr 30, 2020 at 23:27 | comment | added | Gordon Davisson |
Concerning different "flavors" of regex: by default, grep uses "Basic Regular Expression" (BRE) syntax, which is... very basic. grep -E will use "Extended Regular Expression" (ERE) syntax, which is actually still pretty basic. Some versions of grep accept a -P option, which invokes "Perl-Compatible Regular Expression" (PCRE) syntax, which is much closer to most other modern flavors.
|
|
| Apr 30, 2020 at 22:26 | comment | added | Olivier Dulac | @dbates: as for the shell itself, you may want to have a thorough read of several informations on : mywiki.wooledge.org (read the whole bashFAQ, then the marvellous bashpitfalls part (which applies to many other shells as well), and then the bashGuide). all good stuff. | |
| Apr 30, 2020 at 22:23 | comment | added | Olivier Dulac |
@dbates: another thing to be careful about: there are many "flavors" of regular expressions, and also different implementations of each flavor... sometimes you'll to a s/first\(second\)thirdregexp/\1/ to keep just the thing matched by "second" (as a regexp), sometimes you will have to use non-backslashed parenthesis to do the same. and maaany other variations. I like the informations on : regular-expressions.info, and a cool tool (regular-expressions.info/regexbuddy.html) "emulates the regular expression flavors of 262 applications and programming languages"
|
|
| Apr 30, 2020 at 22:01 | comment | added | Olivier Dulac | @dbates: you got it :) single quotes are rarely part of the regexp, so just singlequoting the regexp should pass it "as is" to the grep (or rather, egrep) command. | |
| Apr 30, 2020 at 17:40 | comment | added | dbates |
So it sounds like one way to try to learn this stuff is to follow along with the online resources like regex.com and learn the regular expression syntax there, but put everything inside single quotes when I'm trying it out with grep on the command line (unless I need to actually grep a single quote, then I'll have to jump through the hoops described above.) That way, I can learn one set of syntax commands, and it should work reasonably well with both the online sites and grep at the command line. At least I'll get some consistency as I try to learn the basics.
|
|
| Apr 30, 2020 at 17:34 | vote | accept | dbates | ||
| Apr 30, 2020 at 17:34 | |||||
| Apr 30, 2020 at 5:57 | history | edited | Olivier Dulac | CC BY-SA 4.0 |
added 25 characters in body; added 90 characters in body
|
| Apr 30, 2020 at 5:46 | history | edited | Olivier Dulac | CC BY-SA 4.0 |
added 216 characters in body; deleted 5 characters in body; added 2 characters in body; added 34 characters in body
|
| Apr 30, 2020 at 5:41 | history | answered | Olivier Dulac | CC BY-SA 4.0 |