Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm almost inclined to say that's a bug in grep ... if ANYTHING
I would have expectd "[[]]" to give the desired result, rather than
"two consecutive empty character classes" ... about to check how that
works with other tools (e.g. perl, awk, sed, emacs ... )
I'm almost inclined to say that's a bug in grep ... if ANYTHING
I would have expectd "[[]]" to give the desired result, rather than
"two consecutive empty character classes" ... about to check how that
works with other tools (e.g. perl, awk, sed, emacs ... )
In re other tools, I have read Mastering Regular Expressions http://regex.info/ some time ago and it pointed out that each lang/tool that has a regex engines tends to have differences that vary from minor to major, unless using the pcre option.
Highly recommended book btw.
In re other tools, I have read Mastering Regular Expressions http://regex.info/ some time ago and it pointed out that each lang/tool that has a regex engines tends to have differences that vary from minor to major, unless using the pcre option.
Highly recommended book btw.
Highly recommended indeed - but my copy is at home and
not at my desk ;}
Testing this has now gotten me into the 3rd bottle of Excedrin.
First, I think is a Regex thing and not just a GREP thing.
Here is what I think is happening:
[[]] means [ in the character class, followed by another literal ]---ie it matches only []
[[\] means a character class of [ and literal \----ie it matches [ or \ (\ is not an escape!)
[[\]] means the above + a literal ]----ie it matches ([ OR \) AND ]
So---inside a character class ([....]):
1: [ or ] are literal
2: \ is literal if there is nothing else around but [ or ]
3: Extra [ or ] after a char class are literal (how about before)
Testing this has now gotten me into the 3rd bottle of Excedrin.
First, I think is a Regex thing and not just a GREP thing.
Yes, I'm afraid you're right; I still don't understand WHY,
though.
Quote:
Originally Posted by pixellany
Here is what I think is happening:
[[]] means [ in the character class, followed by another literal ]---ie it matches only []
But that's not how character classed are supposed to work;
and if the outer [] were taken as a class [][] and [[]]
should be equivalent (which they're not). E.g., "[ab]" is
meant to to be "either a or b will do".
My *guess* is that, since [][] works, and we get matches for
any combo of individual or paired square brackets for some
reason the regex implementation "expects" to get a named
character class when it finds two opening [[ brackets, and
then gives up if there's no :<something_posix>: in there.
Postulate:
Whenever "[" is encountered, the following characters are taken as literal --until the first "]". After that, "]" is literal, but "[" is not
the only thing I have not tested is some **other** special characters inside the char class.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.