Regex to catch all files but those starting with "."

tmslnz picture tmslnz · May 26, 2010 · Viewed 10.4k times · Source

In a directory with mixed content such as:

.afile
.anotherfile
bfile.file
bnotherfile.file
.afolder/
.anotherfolder/
bfolder/
bnotherfolder/

How would you catch everything but the files (not dirs) starting with .?
I have tried with a negative lookahead ^(?!\.).+? but it doesn't seem to work right.
Please note that I would like to avoid doing it by excluding the . by using [a-zA-Z< plus all other possible chars minus the dot >]

Any suggestions?

Answer

Martin picture Martin · May 26, 2010

This should do it:

^[^.].*$

[^abc] will match anything that is not a, b or c