I'm learning about regular expression, and they are divided into basic and extended.
Basic Regular Expression(BRE) uses meta-character [ ] ^ $ . *
.
It's works on grep
command well. But, when we use ls
, echo
or something else command, it works well, too.(For example, ls -al [abc]*.txt
)
But, when I learn section about pathname expansion, it uses BRE's metacharcter.
So, I think they are same. Am I right?
$
,.
have no special meaning above pathname expansion. But, still works^
character. When I usels -al [^ab]abc.txt
, it shows me aboutkabc.txt
– A.Cho Feb 20 '16 at 04:10[]
. It isn't necessarily true for all compliant shells. Bash does, dash doesn't. – muru Feb 20 '16 at 05:17grep
forfoo
, you may findcatfood
, and if yougrep
forfoo.*bar
, you may findcatfood at bargain prices
. To find onlyfoo
you need togrep
for^foo$
; to find onlyfoo123%bar
, etc., you need togrep
for^foo.*bar$
. But a wildcard offoo*bar
*doesn't* match a file calledcatfood_bargain
, so you don't need to dols -al ^foo*bar$
. – Scott - Слава Україні Feb 20 '16 at 06:55