RegEx - character class containing brackets, how to escape correctly
Hey there,
somewhat dim question I guess, but: I'm trying to figure out how to grep for a character class like [a-d\[\]\*]. Which, as I see it, should match any of abcd[]*, but doesn't in grep. Also trying to match a class containing both single and double quotes. No particular reason, just trying to get a better handle on grep and REs. Now, I came across a statement suggesting that there is no actual escaping in greps BREs, but rather in the shell, however this post suggests there is both simultaneously, so I tried double escaping like '[a\\'b]' - which doesn't work either. So, I am very confused as to how the escaping works and why it doesn't in these particular instances. Also, something that deeply weirds me out: when I forget to quote a character class grep always matches capital C's and nothing else. Why on earth? //okay, now I just noticed something that really freaks me out: when I try to match '[a\-b]' grep matches a, b and every digit. Why? Best wishes |
Quote:
GNU Grep manual: Character Classes and Bracket Expressions: Quote:
Code:
grep '[][abcd*]' Quote:
Quote:
|
Thanks a lot!
Sorry I wasn't thorough enough - I even was on that page but at a glance assumed it would not help me. |
All times are GMT -5. The time now is 06:04 AM. |