I want to split a requested url filename chunks of up to 2 characters and then rewrite to a directory structure:
Input (line-by-line):
a.txt
ba.txt
cba.txt
dcba.txt
edcba.txt
fedcba.txt
gfedcba.txt
hgfedcba.txt
Desired Output:
a/file.txt
ba/file.txt
c/ba/file.txt
dc/ba/file.txt
e/dc/ba/file.txt
fe/dc/ba/file.txt
g/ef/dc/ba/file.txt
hg/ef/dc/ba/file.txt
Achived output (with regex following):
///a/file.txt
///ba/file.txt
//c/ba/file.txt
//dc/ba/file.txt
/e/dc/ba/file.txt
/fe/dc/ba/file.txt
g/fe/dc/ba/file.txt
hg/fe/dc/ba/file.txt
RegEx:
([a-z]{1,2}?)??([a-z]{1,2}?)??([a-z]{1,2}?)??([a-z]{1,2})??\.txt
Replacement:
$1/$2/$3/$4/file.txt
I found no way to repeat a match and capture each iteration.
Unfortunately even if a match $1 – $3 is not found a slash will be written by this replacement text.
found a way using .NET Group.Captures Property
LinqPad snippet:
LinqPad output:
now i’m going to write an custom IIS Url Rewrite Provider