<p>I am trying to match the folder name in a relative path using C#. I am using the expression: <code>"/(.*)?/"</code> and reversing the matching from left to right to right to left.
When I pass <code>"images/gringo/"</code> into the regular expression, it correctly gives me <code>"gringo"</code> in the first group - I'm only interested in what is between the brackets.
When I pass in <code>"images/"</code>, it fails to pick up <code>"images"</code>. 
I have tried using <code>[/^]</code> and <code>[/$]</code> but neither work.</p>

<p>Thanks,
David</p>

You're probably better off using the
System.IO.DirectoryInfo
class to interpret your relative path. You can then pick off folder or file names using its members:
```
```
DirectoryInfo di = new DirectoryInfo("images/gringo/");
Console.Out.WriteLine(di.Name);
```
```
This will be much safer than any regexps you could use.