|
-
Mar 10th, 2004, 11:07 AM
#1
Thread Starter
Frenzied Member
Regular Expressions
I'm having trouble working out a regular expression to do the following.
I have a string that can contain text in the following formats:
/
/imex
/imex/design
/imex/design/layouts
/other
/other/test
/other/test/something
/other/test/something/etc
(There is no limit to the number of subdirectories.)
I need to get the text between the second and third forward slashes OR the text between the second forward slash and the end of the string if a there isn't a third forward slash OR if there isn't a second forward slash return String.Empty.
So the example above would give:
String.Empty
String.Empty
design
design
String.Empty
test
test
test
Note the regular expression should be case insensitive.
Any help would be appreciated - I'm new to C# so take it slow!
DJ
-
Mar 10th, 2004, 12:53 PM
#2
Addicted Member
Well heres a pattern I'm not great at regex an I am at work so I am not sure if it works or not. Group 2 would return the second subdir or an empty string if there was nothing there.
Code:
/.*?(/(.*?)/?)?((/(.*?))+)?
You could also try using the Split function in the regex class
http://msdn.microsoft.com/library/de...plittopic1.asp
or the more basic approach using the IndexOf property of the string class
http://msdn.microsoft.com/library/de...exoftopic2.asp
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|