I am attempting to retrieve the relative identifier (RID) from the security identifier (SID), which as I understand is the last sequence of numbers on the SID. I received a code example that uses regular expressions to retrieve the value, but I am new to RegEx (see link below). So, before I go using it without fully understanding it, my question is this: is there a reason to use RegEx as opposed to just getting the right most value before the last '-' in the string?
// Retrieve the RID from the SID.
string strObjectSid = "S-1-5-21-397955417-62688126-188441444-1010";
var reg = new Regex( @"^S.*-(\d+)$" );
var match = reg.Match(strObjectSid);
var rid = match.Groups[1].Value;
The expected result for rid is 1010.
Active Directory: DirectoryEntry member list <> GroupPrincipal.GetMembers()
In addition, I tried retrieving the RID attribute from AD but it is not available. Microsoft does not provide any method for retrieving the RID. I know this may seem like a silly question, but this value is important for what I am trying to accomplish, so it needs to be correct along with whatever method I implement to retrieve it.