Regular expression help wanted!

lottap

Newcomer
Joined
Jan 26, 2004
Messages
1
Hi!

I´m having problems with matching a string with a regular expression. The string looks something like this:

xxx\xxx\xxx\xxx

I´m trying to get the last two part of the path, i.e xxx\xxx. The regex I´ve been using is:

^/\.*/\.*$[^/\]

Shouldn´t this work? Any other suggestions?

I´m using the class System.Tex.RegularExpressions.Regex and it throws an exception saying that "parsing "^/\.*/\.*$[^/\]" - Unterminated [] set." What does that mean?

Regards,
lottap
 
i am not familar with regex but maybe this can help


int position = 0;
string path = "xxx\xxx\xxx\xxx";
position = path.LastIndexOf('\\');
string temp = path.Substring(0, position -1);
position = temp.LastIndexOf('\\');

string wanted = path.Substring(position+1);


this is a workaround
 
Visual Basic:
        Dim s As String = "1xx\x2x\abc\987"
        Const e As String = "([^\\]+)\\([^\\]+)$"

        With Regex.Match(s, e)
            Console.WriteLine(.Groups(1).Value())  '' abc
            Console.WriteLine(.Groups(2).Value())  '' 987
        End With
 
Last edited:
Back
Top