Results 1 to 2 of 2

Thread: Regular Expressions

  1. #1

    Thread Starter
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    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

  2. #2
    Addicted Member
    Join Date
    Jun 2003
    Location
    Birmingham, AL
    Posts
    188
    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
  •  



Click Here to Expand Forum to Full Width