Regular expression to retrieve everything before first slash

Posted by alex on Stack Overflow See other posts from Stack Overflow or by alex
Published on 2010-03-11T15:50:35Z Indexed on 2010/05/16 17:30 UTC
Read the original article Hit count: 236

Filed under:
|
|

I need a regular expression to basically get the first part of a string, before the first slash ().

For example in the following:

C:\MyFolder\MyFile.zip

The part I need is "C:"

Another example:

somebucketname\MyFolder\MyFile.zip

I would need "somebucketname"

I also need a regular expression to retrieve the "right hand" part of it, so everything after the first slash (excluding the slash.)

For example

somebucketname\MyFolder\MyFile.zip

would return

MyFolder\MyFile.zip.

© Stack Overflow or respective owner

Related posts about regex

Related posts about c#