philw Posted June 30, 2008 Share Posted June 30, 2008 Couple of questions about regular expressions.1. Supposing I have a string such as "The cat sat on the mat". Is it possible to construct a regular expression that would remove all a's between "cat" and "mat", while leaving "cat" and "mat" unchanged? (Output would be "The cat st on the mat".)2. I want to search for strings such as "_some text_" and replace the underscores with "<i>" and "</i>", while leaving the text between them unchanged. (Output would be "<i>some text</i>".) Is this possible?Thanks! Link to comment Share on other sites More sharing options...
monoceres Posted June 30, 2008 Share Posted June 30, 2008 I'm not very good at Regular expressions but this will do just fine on the second one $string="_some text_ _some more text_" Do $string=StringRegExpReplace(StringRegExpReplace($string,"_*_","<i>",1),"_*_","</i>",1) Until @extended=0 MsGbox(0,"Formatted string",$string) Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
nobbe Posted June 30, 2008 Share Posted June 30, 2008 http://regexlib.com/default.aspx Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 30, 2008 Moderators Share Posted June 30, 2008 Pretty fugly:$s_1 = "The cat sat on the mat" $s_out_1 = StringRegExpReplace($s_1, "(cat)((.*?)(a)(.*?))*(mat)", "\1\3\5\6") ConsoleWrite($s_out_1 & @CRLF) $s_2 = "_some text_ and we can go _on more to see if it_ works or not" $s_out_2 = StringRegExpReplace($s_2, "(_)(.*?)(_)", "<i>\2\<\\i>") ConsoleWrite($s_out_2 & @CRLF) Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
philw Posted June 30, 2008 Author Share Posted June 30, 2008 Many thanks to everyone for the replies! Still trying to get my head round them, as they are way beyond my current level, but hopefully they should solve the problem!Just a quick question , SmOke_N: could you explain what the characters "\1\3\5\6" mean in the first expression? Sorry for my ignorance, but I haven't come across anything like that before. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 30, 2008 Moderators Share Posted June 30, 2008 Many thanks to everyone for the replies! Still trying to get my head round them, as they are way beyond my current level, but hopefully they should solve the problem!Just a quick question , SmOke_N: could you explain what the characters "\1\3\5\6" mean in the first expression? Sorry for my ignorance, but I haven't come across anything like that before.Well the first expression without a loop doesn't really matter anyway, as I can't get it to backtrack through all the "a"'s.The \1\3 etc... those are back referencing the data between the parenthesis to display again (A quick look in the help file under that function would have shown you that ). Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
philw Posted June 30, 2008 Author Share Posted June 30, 2008 Well the first expression without a loop doesn't really matter anyway, as I can't get it to backtrack through all the "a"'s.The \1\3 etc... those are back referencing the data between the parenthesis to display again (A quick look in the help file under that function would have shown you that ).Well, I did look at the help file, as well as the one for String RegExp, but I didn't really understand it. Guess I'll have to find a beginner's guide to regular expressions! Must be one on the net somewhere... Link to comment Share on other sites More sharing options...
zorphnog Posted June 30, 2008 Share Posted June 30, 2008 Try http://www.regular-expressions.info/tutorial.html. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 30, 2008 Moderators Share Posted June 30, 2008 Well, I did look at the help file, as well as the one for String RegExp, but I didn't really understand it. Guess I'll have to find a beginner's guide to regular expressions! Must be one on the net somewhere...I was referring to the back reference answer being in the help file in the parameters information.http://weitz.de/regex-coach/ Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
philw Posted June 30, 2008 Author Share Posted June 30, 2008 Thanks very much for the suggestions. It'll give me some where to start! 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