iamtheky Posted December 30, 2014 Share Posted December 30, 2014 (edited) desired output (removing all instances of $name from $string) du2: ad,43|gshy: 3d3,adf You want more than just $name then, as 3 of the 4 pipes are gone as well? so removes name and trailing separators first, and then the second pass cleans up the end where you want the preceding separator and name removed. $string = "gsh: kae,as|du2: ad,43|gsh: kae,as|gshy: 3d3,adf|gsh: kae,as" $name = "gsh: kae,as" $sep="|" $stripped = stringreplace($string , $name & $sep, "") $stripped = stringreplace($stripped , $sep & $name , "") msgbox(0, '' , $stripped) Edited December 30, 2014 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
gcue Posted December 30, 2014 Author Share Posted December 30, 2014 If the separator is not the same, you should change it in the regex, or use a variable for this. ; $name = "gsh" ; $string = "gsh,as,43,abgsh,adf,gsh,gsh" ; $separator = "," $name = "gsh: kae,as" $string = "gsh: kae,as|du2: ad,43|gsh: kae,as|gshy: 3d3,adf|gsh: kae,as" $separator = "|" $final = StringRegExpReplace($string, "(?:(\Q" & $separator & "\E)(\Q" & $name & "\E)(?=(?1)|\Z))|(?:\A(?2)(?1)|\Z)", "") MsgBox(0, "", $final) works great!! thank you very much Link to comment Share on other sites More sharing options...
gcue Posted December 30, 2014 Author Share Posted December 30, 2014 You want more than just $name then, as 3 of the 4 pipes are gone as well? so removes name and trailing separators first, and then the second pass cleans up the end where you want the preceding separator and name removed. $string = "gsh: kae,as|du2: ad,43|gsh: kae,as|gshy: 3d3,adf|gsh: kae,as" $name = "gsh: kae,as" $sep="|" $stripped = stringreplace($string , $name & $sep, "") $stripped = stringreplace($stripped , $sep & $name , "") msgbox(0, '' , $stripped) only problem with that is if the name is slightly different at the beginning or end Link to comment Share on other sites More sharing options...
mikell Posted December 30, 2014 Share Posted December 30, 2014 (edited) BrewManNH extended $name = "gsh: kae,as" $string = "gsh: kae,as|du2: ad,43|gsh: kae,as|gshy: 3d3,adf|gsh: kae,as" $separator = "|" $final = StringRegExpReplace($string, _ '(\Q' & $name & $separator & '\E?)|(\Q' & $separator & '\E?\Q' & $name & '\E)', "") MsgBox(0, "", $final) Edited December 30, 2014 by mikell Link to comment Share on other sites More sharing options...
kylomas Posted December 30, 2014 Share Posted December 30, 2014 (edited) @mikell - That pattern fails on... $name = "gsh: kae,as" $string = "gsh: kae,as|du2: ad,43|gsh: kae,asx|gshy: 3d3,adf|gsh: kae,as" $separator = "|" $final = StringRegExpReplace($string, _ '(\Q' & $name & $separator & '\E?)|(\Q' & $separator & '\E?\Q' & $name & '\E)', "") MsgBox(0, "", $final) @gcue - You're requirements are a long way from where we started, please define the complete strings that you are working with... Edited December 30, 2014 by kylomas JLogan3o13 1 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...
Moderators JLogan3o13 Posted December 30, 2014 Moderators Share Posted December 30, 2014 @gcue - You're requirements are a long way from where we started, please define the complete strings that you are working with... Amen, you have us floundering about here as your requirements change. Help us help you and provide exactly what you're looking for please! "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
mikell Posted December 30, 2014 Share Posted December 30, 2014 (edited) @gcue - You're requirements are a long way from where we started, please define the complete strings that you are working with... Sooo obvious... it's the usual trouble in most questions concerning regex Edit BTW jguinch's regex in post #20 still works and seems the best (the only..) way Edited December 30, 2014 by mikell Link to comment Share on other sites More sharing options...
kylomas Posted December 30, 2014 Share Posted December 30, 2014 BTW jguinch's regex in post #20 still works and seems the best (the only..) way Yes, and now I'm going to spend the next couple hours trying to figure it out... jguinch 1 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...
iamtheky Posted December 30, 2014 Share Posted December 30, 2014 (edited) it may be the best, but it is not the parenthetical only. #21 absolutely returns the desired output from the given input (that the input has undisclosed variations is not the scripts fault). Edited December 30, 2014 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
mikell Posted December 30, 2014 Share Posted December 30, 2014 Yes, but it fails on kylomas' variation from #25 Anyway when it becomes really tricky with hazardous and variable requirements then the most reliable way remains StringSplit + ArrayDelete + ArrayToString ^^ Link to comment Share on other sites More sharing options...
iamtheky Posted December 30, 2014 Share Posted December 30, 2014 ahhh, i see now, variations in the string not the name. And for sure if there were any amount of those I would totally go the stringsplit route. Or go learn RegEx like JG. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
kylomas Posted December 30, 2014 Share Posted December 30, 2014 Or go learn RegEx like JG. *sigh* been try'in, been fail'in... 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...
mikell Posted December 30, 2014 Share Posted December 30, 2014 Keep fight'in Link to comment Share on other sites More sharing options...
jguinch Posted December 30, 2014 Share Posted December 30, 2014 (edited) @kylomas : what is so hard to understand in the pattern ? Do you need explanations ? Edit : here is a good way to understand it (I think) : https://regex101.com/r/iR0dK7/1 Edited December 30, 2014 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF 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