kor Posted February 10, 2015 Share Posted February 10, 2015 I have a piece of data CN=308-142413,OU=Workstations,OU=Administrative,OU=Admin-Sites,DC=TEST,DC=COMPANY,DC=ORG I would like to delete everything before the first OU statement (ou=workstations) effectively getting rid of CN=308-142413, (including that pesky comma) But I'm not sure how to accomplish this deletion without accidentally deleting the rest of the string (if I based things on commas, or OU) Link to comment Share on other sites More sharing options...
Solution mikell Posted February 10, 2015 Solution Share Posted February 10, 2015 (edited) $str = "CN=308-142413,OU=Workstations,OU=Administrative,OU=Admin-Sites,DC=TEST,DC=COMPANY,DC=ORG" $res = StringRegExpReplace($str, '^.*?,' , "") Msgbox(0,"", $res) Means : delete anything .*? between the beginning ^ and the comma , (comma included) Edit Don't forget the classic way $str = "CN=308-142413,OU=Workstations,OU=Administrative,OU=Admin-Sites,DC=TEST,DC=COMPANY,DC=ORG" $res = StringReplace($str, StringSplit($str, ",")[1] & ",", "") Msgbox(0,"", $res) Edit2 If "everything before the first OU" may include a comma, it could be done like this $str = "CN=308-142413,something,OUelse,OU=Workstations,OU=Administrative,OU=Admin-Sites,DC=TEST,DC=COMPANY,DC=ORG" $res = StringRegExpReplace($str, '^.*?(OU=.*)' , "$1") Msgbox(0,"", $res) Edited February 10, 2015 by mikell Link to comment Share on other sites More sharing options...
kor Posted February 10, 2015 Author Share Posted February 10, 2015 Thank you so much. Link to comment Share on other sites More sharing options...
kylomas Posted February 11, 2015 Share Posted February 11, 2015 mikell's last pattern is the correct one if your predicate string can contain more than one comma as in ... local $str = 'CN=308-142413,fouteen,OU=Workstations,OU=Administrative,OU=Admin-Sites,DC=TEST,DC=COMPANY,DC=ORG' $res = StringRegExpReplace($str, '^.*?(OU=.*)' , "$1") Msgbox(0,"", $res) Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
jguinch Posted February 11, 2015 Share Posted February 11, 2015 @kylomas : the comma should me escaped in this case : local $str = 'CN=308-142413\,fouteen,OU=Workstations,OU=Administrative,OU=Admin-Sites,DC=TEST,DC=COMPANY,DC=ORG' http://social.technet.microsoft.com/wiki/contents/articles/5312.active-directory-characters-to-escape.aspx Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
kylomas Posted February 12, 2015 Share Posted February 12, 2015 @jguinch - Yes, but I am not going to make assumptions/force requirements on user input. Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now