TheDcoder Posted March 14, 2016 Posted March 14, 2016 Hello , I am trying to find the best way to spilt this string: :<nick>!<host mask> PRIVMSG <channel/nick> :<message> into an array like this: Global Enum $SENT_BY, $HOST_MASK, $SENT_TO, $MESSAGE $aArray[$SENT_BY] = "<nick>" $aArray[$HOST_MASK] = "<host mask>" $aArray[$SENT_TO] = "<channel/nick>" $aArray[$MESSAGE] = "<message>" (Stuff between <> is dynamic) I can do that with inefficient code but I think it is possible to do it more efficiently with RegEx Thanks in Advance! TD P.S Yeah, that is the raw format of a message received in IRC EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
jchd Posted March 14, 2016 Posted March 14, 2016 You mean like this: #include <Array.au3> Local $sIn = ":<nick>!<host mask> PRIVMSG <channel/nick> :<message> ... and why not >this or that< " Local $aOut = StringRegExp($sIn, "<[^>]*>", 3) _ArrayDisplay($aOut) 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)
TheDcoder Posted March 14, 2016 Author Posted March 14, 2016 @jchd Perfect! Thanks! EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
TheDcoder Posted March 14, 2016 Author Posted March 14, 2016 @jchd Ooops! I think you misunderstood, here is a example: ; :<nick>!<host mask> PRIVMSG <channel/nick> :<message> #include <Array.au3> Local $sIn = ":TheDcoder!anything_could_be_here PRIVMSG TheDcoder :Foobar" Local $aOut = StringRegExp($sIn, "<[^>]*>", 3) _ArrayDisplay($aOut) I used <> to denote variable content Thanks in Advance, TD EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
jguinch Posted March 14, 2016 Posted March 14, 2016 @TheDcoder, your first message was not clear enough. I understood the same thing than jchd. #include <Array.au3> Local $sIn = ":TheDcoder!anything_could_be_here PRIVMSG TheDcoder :Foobar" Local $aOut = StringRegExp($sIn, ":(.+?)!(.+?) PRIVMSG (.+?) :(\N+)", 3) _ArrayDisplay($aOut) TheDcoder 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
TheDcoder Posted March 14, 2016 Author Posted March 14, 2016 @jguinch Thanks! 4 minutes ago, jguinch said: your first message was not clear enough Sorry! Is there a way to validate if a string is in that format? EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
jguinch Posted March 14, 2016 Posted March 14, 2016 Yes, you can do like this : #include <Array.au3> Local $sIn = ":TheDcoder!anything_could_be_here PRIVMSG TheDcoder :Foobar" Local $aOut = StringRegExp($sIn, "^:(.+?)!(.+?) PRIVMSG (.+?) :(\N+)$", 3) If Not @error Then _ArrayDisplay($aOut) EndIf TheDcoder 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
TheDcoder Posted March 14, 2016 Author Posted March 14, 2016 :facepalm: Thanks for your help! EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
andrei0x309 Posted March 14, 2016 Posted March 14, 2016 3 minutes ago, TheDcoder said: :facepalm: Thanks for your help! Do you want the spaces after and before: PRIVMSG ? The regex will work only if you have spaces around it.
TheDcoder Posted March 14, 2016 Author Posted March 14, 2016 Nope, The spaces are always there EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
TheDcoder Posted March 22, 2016 Author Posted March 22, 2016 I need some help with splitting again guys (Its a different syntax this time): {"responseData": {"results":[{"GsearchResultClass":"GwebSearch","unescapedUrl":"http://www.userbars.be/showroom/TheDcoder","url":"http://www.userbars.be/showroom/TheDcoder","visibleUrl":"www.userbars.be","cacheUrl":"http://www.google.com/search?q\u003dcache:TD31scizJEEJ:www.userbars.be","title":"Userbars | Userbar Showroom » \u003cb\u003eTheDcoder\u003c/b\u003e - Userbars.be","titleNoFormatting":"Userbars | Userbar Showroom » TheDcoder - Userbars.be","content":"Userbars Showroom \u003cb\u003eTheDcoder\u003c/b\u003e: firefox, keepass, password, manager, life, is, a, \ndonut, autoit, scripter, kongregate, pc, nerd."}],"cursor":{"resultCount":"555","pages":[{"start":"0","label":1},{"start":"1","label":2},{"start":"2","label":3},{"start":"3","label":4},{"start":"4","label":5},{"start":"5","label":6},{"start":"6","label":7},{"start":"7","label":8}],"estimatedResultCount":"555","currentPageIndex":0,"moreResultsUrl":"http://www.google.com/search?oe\u003dutf8\u0026ie\u003dutf8\u0026source\u003duds\u0026start\u003d0\u0026hl\u003den-GB\u0026q\u003dTheDcoder","searchResultTime":"0.10"}}, "responseDetails": null, "responseStatus": 200} (Source: Google AJAX Web Search API) I want to extract these two from that text: http://www.userbars.be/showroom/TheDcoder Userbars | Userbar Showroom » TheDcoder - Userbars.be (Use a text editor to find them.) Thanks in Advance, TD EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
Danyfirex Posted March 22, 2016 Posted March 22, 2016 any problem using stringBetween? Local $sIn = "yourstr" Local $Str1=_StringBetween($sIn,'"url":"','"')[0] Local $Str2=_StringBetween($sIn,'"titleNoFormatting":"','"')[0] ConsoleWrite($Str1 & @CRLF) ConsoleWrite($Str2 & @CRLF) Saludos TheDcoder 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
TheDcoder Posted March 23, 2016 Author Posted March 23, 2016 Purrrrfect! EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
jguinch Posted March 23, 2016 Posted March 23, 2016 Also, a regex way : $aVal = StringRegExp($sIn, '"(?:url|title)":"([^"]+)"', 3) ConsoleWrite($aVal[0] & @CRLF & $aVal[1]) TheDcoder 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
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