Via this post I found a way to get the last part of a string after a slash.
I need to use a slight modification of this:
I could use a regex that would match "Everything after the second-to-last backslash".
I rewrote the original to use backslash like this:
([^\\]+$)
And I made this code and test
public static string TrimTrail(this string value, string pattern)
{
var regEx = new Regex(pattern);
var result = regEx.Match(value);
return result.Value;
}
[Test]
public void TestOfTrimmingTrail()
{
//Arrange
var stringToTest = @"0001 Lorem ipsum dolor sit\011 tortor neque\ 0111\interdum magn";
var pattern = @"([^\\]+$)";
//Act
var result = stringToTest.TrimTrail(pattern);
//Assert
Assert.AreEqual(" 0111\\interdum magn", result);
}
But since I haven't been able to figure out the "second-to-last" requirement, it only returns
Expected string length 19 but was 13. Strings differ at index 0.
Expected: " 0111\\interdum magn"
But was: "interdum magn"
-----------^
I tried adding a {2}
before the negation char, but with no luck.
Can you help me figure out the remaining part?
Thanks :-)