I'd like a regular expression to match the leading 4 characters of a string in .NET.
To be more specific, I'm using the
substring method to search for the 1st occurrence of a piece of string and the 4 characters that precede it.
Let's say I have a string like this:
..In my code, this is what I do
string s = "adgstuoppdnmudio hjdk.ABCD kglog doplsjood" string x = s.Substring(s.IndexOf("ABCD"))
...This is what I get,
x = "adgstuoppdnmudio hjdk.ABCD" what I'm looking for is how to get the 5 characters before ABCD in the above string (hjdk.) so that my final string is "hjdk.ABCD".
I could probably use a
char Array then the reverse function that comes with it so that I can read my string backward but I believe a regex will work faster hence in my question title I stressed 'using regular expression'.