Question

I have the following SDDL:

O:BAG:BAD:(A;;CCDCLCSWRP;;;BA)(A;;CCDCSW;;;WD)(A;;CCDCLCSWRP;;;S-1-5-32-562)(A;;CCDCLCSWRP;;;LU)(A;;CCLCRP;;;S-1-5-21-4217728705-3687557540-3107027809-1003)

Unfortunately I keep getting this:

(A;;CCDCLCSWRP;;;BA)(A;;CCDCSW;;;WD)

And what I want is just (A;;CCDCSW;;;WD).

My regex is: (\(A;.+;WD\)) : find "(A;" some characters ending in ";WD)"

I've tried making the match lazy and I've tried excluding the ")(" pair of characters based on a search of the stackoverflow regex tag looking for examples where others have answered similar questions.

I'm really confused why the exclusion of the parens isn't working:

(\(A;.+[^\(\)]*.+;WD\)) : find "(A;" followed by some characters where none of them are ")('' followed by other characters ending in ";WD)"

And this was my guess at using negative look around:

(\(A;.+^((?!\)\().).+;WD\)) 

which didn't match anything.

I'm also doing this in PowerShell v3.0 with the following code:

$RegExPattern = [regex]"(\($ACE_Type;.*;$ACE_SID\))+?"
if ($SDDL -match $RegExPattern) {
    $MatchingACE = $Matches[0]

Where in this instance $ACE_Type = "A" and $ACE_SID = "WD".

Était-ce utile?

La solution

You almost had the solution with your second regex pattern. The problem was that you included too many . wildcards. This should be all you need:

A;[^()]+;WD

And of course if you just want to capture the string in between A; and ;WD:

A;([^()]+);WD

Then just replace with \1.

Autres conseils

I simplified this a lot and then added lookarounds so that you only matched the intended string (in between A;...;WD). This looks behind for A;, then matches 1+ non-parenthesis characters, while looking ahead for ;WD.

(?<=A;)[^()]+(?=;WD)

Regex101

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top