LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 04-21-2010, 10:22 PM   #16
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910

Quote:
Originally Posted by pixellany View Post
Postulate:
Whenever "[" is encountered, the following characters are taken as literal --until the first "]". After that, "]" is literal, but "[" is not
Nice, but:
That wouldn't explain why [][] gives the desired result. :/
 
Old 04-21-2010, 11:06 PM   #17
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Quote:
Whenever "[" is encountered, the following characters are taken as literal --until the first "]". After that, "]" is literal, but "[" is not
Not sure this holds true for the previous example of:
Code:
[][]
Based on your postulation we meet the first "]" immediately so should this not then be deemed to be two empty character sets?
 
Old 04-21-2010, 11:11 PM   #18
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 333

Rep: Reputation: 141Reputation: 141
From the regular expression section of the grep man page
Quote:
To include a literal ] place it first in the list.
Or, from the Grymoire tutorial
http://www.grymoire.com/Unix/Regular.html#uh-6
Quote:
Like the anchors in places that can't be considered an anchor, the characters "]" and "-" do not have a special meaning if they directly follow "[".
 
Old 04-21-2010, 11:13 PM   #19
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Touche!!!

Add to the postulate: It continues to the first "]" assuming that there is something in the character set. We have to assume that there is a simple and deterministic rule in effect.....

"[][]" in fact matches "]" OR "["
 
Old 04-22-2010, 12:09 AM   #20
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
OK, so based on the following file:
Quote:
from
a
n
[]
[[
]
s
9
-
][
plus
]]
[
All of the following return the expected results:
Code:
grep -E "[][]" file
grep -E "[][]+" file
grep -E "[][]{2}" file
grep -E "[][9a-]" file //minus had to be last for me here??
All worked equally well with single or double quotes.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular Expressions Wim Sturkenboom Programming 10 11-19-2009 02:21 AM
help with regular expressions mariogarcia Linux - Software 3 01-28-2009 04:23 AM
Regular expressions bhuwan Programming 5 02-26-2006 12:07 AM
regular expressions. stomach Linux - Software 1 02-10-2006 07:41 AM
regular expressions? alaios Linux - General 2 06-11-2003 04:51 PM


All times are GMT -5. The time now is 10:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration