Can't quite understand this regex


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can't quite understand this regex
# 1  
Old 12-28-2008
Can't quite understand this regex

The following regular expression is found in a book I have been reading. It apparently can be used on an /etc/passwd file to find any accounts which have no password. I am having a heck of a time seeing how it works, and I was wondering if someone could run me through it. I will take a stab at what I think it is doing, and then maybe you could correct me where necessary...

Code:
grep '^[^:]*::'

Ok, so what I see here is 'Any line that begins with 0 or more characters that are *not* a colon, followed by two colons in a row. Now I would not have questioned my interpretation of the above except that the example in the book showed that such a grep would yield the following:

Code:
::0:0:::

Which seems to me to be a line that begins with 0 or more colons, which seems to be negated by the way I understand that regular expression. What am I missing?
# 2  
Old 12-29-2008
Hi,

as regards the '^[^:]" your reasoning is right.
But "*" means zero or more occurence, thus a
no-match is a match, too.

So "'^[^:]*::'" matches the "::" part and the "^[^:]" part goes
unrecognised and consequently your term is matched.

HTH Chris
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sendmail K command regex: adding exclusion/negative lookahead to regex -a@MATCH

I'm trying to get some exclusions into our sendmail regular expression for the K command. The following configuration & regex works: LOCAL_CONFIG # Kcheckaddress regex -a@MATCH +<@+?\.++?\.(us|info|to|br|bid|cn|ru) LOCAL_RULESETS SLocal_check_mail # check address against various regex... (0 Replies)
Discussion started by: RobbieTheK
0 Replies

2. Shell Programming and Scripting

Perl, RegEx - Help me to understand the regex!

I am not a big expert in regex and have just little understanding of that language. Could you help me to understand the regular Perl expression: ^(?!if\b|else\b|while\b|)(?:+?\s+){1,6}(+\s*)\(*\) *?(?:^*;?+){0,10}\{ ------ This is regex to select functions from a C/C++ source and defined in... (2 Replies)
Discussion started by: alex_5161
2 Replies

3. Shell Programming and Scripting

understand sed

cat teledir.txt jai sharma 25853670 chanchal singhvi 9831545629 anil aggarwal 9830263298 shyam saksena 23217847 lalit chowdury 26688726 If i use the below command , it is giving me the output with "," in between two name. how ? and also i would like to know the reason for the space used in... (1 Reply)
Discussion started by: Antony Ankrose
1 Replies

4. UNIX for Dummies Questions & Answers

read regex from ID file, print regex and line below from source file

I have a file of protein sequences with headers (my source file). Based on a list of IDs (which are included in some of the headers), I'd like to print out only the specified sequences, with only the ID as header. In other words, I'd like to search source.txt for the terms in IDs.txt, and print... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

5. Shell Programming and Scripting

can't understand!

Hi All, can you please help me to figured out what's the meaning of this. ${SERVER_DATABASE} -b << EOF 2>>/dev/null THanks, (3 Replies)
Discussion started by: nikki1200
3 Replies

6. Shell Programming and Scripting

Converting perl regex to sed regex

I am having trouble parsing rpm filenames in a shell script.. I found a snippet of perl code that will perform the task but I really don't have time to rewrite the entire script in perl. I cannot for the life of me convert this code into something sed-friendly: if ($rpm =~ /(*)-(*)-(*)\.(.*)/)... (1 Reply)
Discussion started by: suntzu
1 Replies

7. UNIX for Dummies Questions & Answers

can't understand this at all.

Ok, i've been trying to write some shell scripts. nothing challenging, but just automating All of the tutorials i read say to start the file with #!/bin/bash or whatever your path to bash is. So i do it, and all of my scripts error out saying ./nameofscript:command not found when i... (4 Replies)
Discussion started by: severndigital
4 Replies

8. UNIX for Dummies Questions & Answers

can't understand

how i can download this game n start it :S (5 Replies)
Discussion started by: BoyArcher
5 Replies
Login or Register to Ask a Question