Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

who says perl is not readable?

Name: Anonymous 2015-11-06 14:25

my $rxParsePath = qr
{(?x) # Use extended regular expression syntax to
# allow comments and white space
^ # Anchor pattern to beginning of string
(?=.) # Zero-width look ahead assertion to ensure
# that there must be at least one character
# for the match to succeed
(.*/)? # A memory grouping (1st) for path, greedy
# match of any characters up to and including
# the rightmost slash (the path part) with a
# quantifier of '?' (0 or 1), i.e. there
# may or may not be a directory part
( # Open memory grouping (2nd) for file name
(.*?) # A memory grouping (3rd) for file name stub
# of a non-greedy match of any character
# without a quantifier since, if there is a
# file name part, at least some of it will
# form a stub otherwise it would be a dot-file
( # A memory grouping (4th) for file name
# extension
(?<=[^/]) # zero width look behind assertion such
# that following pattern will only succeed
# if preceded by any caracter other than
# a slash '/'
\.[^.]+ # a literal dot '.' followed by one or more
# non-dots
)? # Close memory grouping (4th) with a quantifier
# of '?' (0 or 1), i.e. there may or may not
# be a file name extension part
)? # Close memory grouping (2nd) with a quantifier
# of '?' (0 or 1), i.e. there may or may not
# be a file name part
$ # Anchor pattern to end of string
};

Name: Anonymous 2015-11-07 3:05

anyChar = lpeg.P(1)
dotChar = lpeg.P"."
slashChar = lpeg.P"/"
optionalDotChar = dotChar^-1
anyCharButSlash = anyChar - slashChar
anyCharButDot = anyChar - dotChar
oneOrMoreNonDotChars = anyCharButDot ^ 1

followedByAtLeastOneChar = #anyChar
endOfString = lpeg.P(-1)

everythingUpToAndIncludingASlash = anyCharButSlash^0 * slashChar
everythingUpToAndIncludingTheLastSlash = everythingUpToAndIncludingASlash^0
path = everythingUpToAndIncludingTheLastSlash
capturePath = lpeg.C(path)

fileNameExtension = dotChar * oneOrMoreNonDotChars * endOfString
optionalFileNameExtension = fileNameExtension^-1
captureOptionalFileNameExtension = lpeg.C(optionalFileNameExtension)

anyCharNotStartOfFileExtension = anyChar - fileNameExtension
fileNameStub = optionalDotChar * anyCharNotStartOfFileExtension^0
captureFileNameStub = lpeg.C(fileNameStub)

fileName = captureFileNameStub * captureOptionalFileNameExtension
captureFileName = lpeg.C(fileName)

pathPattern = followedByAtLeastOneChar * capturePath * captureFileName

capturePathPattern = lpeg.C(pathPattern)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List