1. Look at the following:
>> fullfile( 'C:\Temp', 'C:\Temp\myFile.txt' )
ans =
C:\Temp\C:\Temp\myFile.txt
>> fullfile( '/home/ted', '/home/ted/myFile.txt' )
ans =
\home\ted\home\ted\myFile.txt
so what is done with the regexp is simply to detect if the drive letter and ':' is already in inPath, or if the path starts with the file separator, both being cases of absolute paths.
2. In the pattern, ^ matches the start of the string, the end of the pattern \ concatenated with the file separator matches the file separator, which has to be escaped in case it's a backlash (special char. for regexp); and the middle of the pattern ()? says "as little as possible" (even 0) match of what is inside parentheses, which is one alphanumeric (or underscore but it's irrelevant here) character matched with the operator \w, followed by a semi-column. This makes the drive letter and ':' optional for managing the UNIX types of absolute paths.
3. It's a list of patterns for ignoring ., .., and the current M-file itself, I guess in a list of file names returned by the DIR function. This could be done using STRCMP instead of REGEXP. As the '.' has a special meaning in regexp patterns (= any character), it has to be escaped.
4. In regexp patterns, ^ matches the beginning of the string and $ matches the end. In 3., you can see that they frame the '\. and '\.\., which limits positive matches to only '.' and '..' and not file names which use the the . as a separator between the name and the extension, or any ill defined file name which contains '..'.
Best Answer