michaelslamet Posted October 24, 2013 Posted October 24, 2013 (edited) I have this string: [Never delete this]And this and dont delete this too I would like to delete and keep the rest (which is "[Never delete this]And this and dont delete this too") So basicly I would like to delete anything that start with "" Second question: Without delete "" I would like to add space (if there is no space) after the "]" so the final string will become: [Never delete this]And this and dont delete this too (note there is a space between "]" and word "and" on the final string) How could I do that? Thank you very much Edit: added second question Edited October 24, 2013 by michaelslamet
Solution kylomas Posted October 24, 2013 Solution Posted October 24, 2013 (edited) Hi ms, long time no talk... Try this... local $str = '[Never delete this]And this [url="http://OnlyDeleteThis.com"]and dont delete this too' ConsoleWrite(stringregexpreplace($str,'(.*)\[url=.*\](.*)','$1 $2') & @LF) kylomas edit: additional info If the pattern to delete occurs multiple times in the string then try this... local $str = '[Never delete this]And this [url="http://OnlyDeleteThis.com"]and dont delete this too' $str &= '[some more text to not delete]And this [url="http://2ND one to delete.com"]keep the end also' ConsoleWrite(stringregexpreplace($str,'\[url=[^\]]+\]',' ') & @LF) Edited October 24, 2013 by kylomas michaelslamet 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
michaelslamet Posted October 24, 2013 Author Posted October 24, 2013 Hi Kylomas, Yes, quite a long time Yes, the pattern is repeated and the second code works great. I spend some times trying to figure out how to make the first code working on repeated pattern, but seems I need to improve my skill and bump, like you can read my mind, you post the second code Thanks a lot, Kylomas
kylomas Posted October 24, 2013 Posted October 24, 2013 (edited) Great, I'm glad it worked. Enjoy your beautiful island... kylomas edit: spelling Edited October 24, 2013 by kylomas 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
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