edgariyu Posted May 2, 2010 Share Posted May 2, 2010 Hi to everyone! I'm new with Autoit, so i hope you could help me starting with this language. Here comes my questions:Let's put the example of these 3 strings:http://www.ejemplo1.comhttp://www.ejemplo2.es/loquesea/xx.htmlhttp://www.problema.solucion.net/loquesea/xdew2/de.html¿There's any way to get the extension of the direccion? I mean, in the first case will be com, in the second es and in the last net.My other question is if it's possible to count the number of times that a character is repeated in a string, for example, count the number of times that the character & is repeated in this string: http://www.ejemplo.com/dsdsada&dsadasda&sds%ddfsd&aThaks to all for your help!! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 2, 2010 Moderators Share Posted May 2, 2010 edgariyu, Welcome to the AutoIt forum. Your first question can be solved like this: $sText = "http://www.ejemplo1.com" $sExt = StringRegExpReplace($sText, "^.*\.", "") MsgBox(0, "Ext", "The extension is: " & $sExt And the the second like this: $sText = "http://www.ejemplo.com/dsdsada&dsadasda&sds%ddfsd&a" StringRegExpReplace($sText, "&", "&") MsgBox(0, "Ext", "The number of '&'s: " & @extended) I hope that helps. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
edgariyu Posted May 2, 2010 Author Share Posted May 2, 2010 Thaks Melba23 for your fast answer!! That was exactly what i was looking for! The only thing that i don't understand at all is in the first piece of code, if you put www.ejemplo1.com/somethingelse/dsdasd , the code take all that goes after the last point (com/smethingelse/...). How could i erase that part? or if you have www.example.other.net/semething and you want to take the "other". I don't understand the patern ^.*\. :s Thaks for your help!!! Link to comment Share on other sites More sharing options...
GEOSoft Posted May 2, 2010 Share Posted May 2, 2010 As much as I have a love-hate relationship with RegEx, using it to answer the second question is perhaps over the top, although it won't really make a lot of difference. The onlt reason I mention it is becuase it may be a bit too soon in the OPs experience with AutoIt to start trying to figure out SREs. Not too mention I forgot to pick on M23 yesterday so I have to catch up today. $sText = "http://www.ejemplo.com/dsdsada&dsadasda&sds%ddfsd&a" StringReplace($sText, "&", "&") $sVal = @Extended MsgBox(0, "Ext", "The number of '&'s: " & $sVal) MsgBox(0, "Result", "The number of repetitions is ", $sVal-1) George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 2, 2010 Moderators Share Posted May 2, 2010 (edited) edgariyu, George will no doubt be along in a minute with a fancy SRE, but this will do just as well: $sText = " www.ejemplo1.com/somethingelse/dsdasd " $aArray = StringSplit(StringRegExpReplace($sText, "^.*\.", ""), "/") MsgBox(0, "Ext", "The extension is: " & $aArray[1]) M23 Edit: I see he beat me too it - but did not leave an SRE. Must be an off day...... edgariyu - we are not always like this, but we do try and have fun if we can. Edited May 2, 2010 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
GEOSoft Posted May 2, 2010 Share Posted May 2, 2010 Edit: I see he beat me too it - but did not leave an SRE. Must be an off day...... edgariyu - we are not always like this, but we do try and have fun if we can. I was waiting for someone whom I shall leave un-named to check his PM's so he could check the expression himself. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
edgariyu Posted May 2, 2010 Author Share Posted May 2, 2010 Thaks both for your quick answers!! Link to comment Share on other sites More sharing options...
jchd Posted May 2, 2010 Share Posted May 2, 2010 (edited) Beyond the excellent answer already provided, let me ask a question:In the case of httm://www.asus.com.tw/index.html what are you expecting: com or tw or com.tw?There are increasingly more and more subdomains in use and this may affect your script(s). Edited May 2, 2010 by jchd This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
edgariyu Posted May 3, 2010 Author Share Posted May 3, 2010 Good question! I expected to get com.tw, and the fact that the URL ends with a .html is a problem too. I solved triming the string when it's necessary, but i don't know how to get the com.tw :s Link to comment Share on other sites More sharing options...
jchd Posted May 3, 2010 Share Posted May 3, 2010 Separating the domain and the path/file parts is not the problem. The issue is more with the trend towards domain names that have more than the historic 3 components. Not only there is an explosion of TLD (top level domains) but the (now independant) national CANNs have a number of "features", well beyond simple vanity. For instance you might encouter www.abcd.domain.com.oz.au and a large number of weird (non-existant or phasing out) country "codes" (.su, .dd, .ac, ...). The advent of IDN is now making identifying TLDs really more difficult, anyway, more than what a single regexp can (reasonably) do. Given that the vast majority of potential web users will find it easier to have urls written in their own (non-latin) scripts, I bet we will see more and more of these unusual domain names. Beside using some tables lookups, I don't see any one liner here. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
edgariyu Posted May 4, 2010 Author Share Posted May 4, 2010 I'm new with regular expresions and it's being kind of hard :sCan anyone tell me how can i get the text between the points text1.whatiwant.text2 for use it in a StringRegExpReplace?I don't know how to tell the pattern to get the text between the twoo points, because using .*\. and replacing it for "" then i get "text2", and with \..* i get the other text1 :sOn purpose, can anyone tell me a page or manual to learn more about regular expresions? (besides of the one of help file )Thanks for your help !! Link to comment Share on other sites More sharing options...
jchd Posted May 4, 2010 Share Posted May 4, 2010 PCRE: follow the link in the help page. This is the definitive PCRE reference. No tutorial, just reference. tools: RexEx Coach is very good and freeware, RegExp Buddy is payware and excellent (albeit PCRE support is years behind) other good tools floating in this forum (sticking to PCRE as implemented by AutoIt). Google and forum search are your friends. Now to extract the part you want: $res = StringRegExpReplace($s, "[^.]*?\.([^.]*?)\..*", "$1") should do it. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
edgariyu Posted May 4, 2010 Author Share Posted May 4, 2010 Thaks jchd for your quick answer! If God were a programer definetly would be your junior I'll take a look on PCRE Link to comment Share on other sites More sharing options...
GEOSoft Posted May 5, 2010 Share Posted May 5, 2010 This is still in Beta but you might want to give it a try for testing and experimenting with PCRE expressions.http://codingwithautoit.blogspot.com/2010/05/pcre-toolkit-beta.html George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
edgariyu Posted May 5, 2010 Author Share Posted May 5, 2010 Thanks for the link GEOSoft 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