Jump to content

Recommended Posts

Posted

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 :D

 

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

Posted

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 here
RegExp tutorial: enough to get started
PCRE 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)

Posted

@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 :P

 

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

Posted

@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)

 

Posted

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

 

Posted
3 minutes ago, TheDcoder said:

:facepalm:

 

Thanks for your help! :thumbsup:

Do you want the spaces after and before:

PRIVMSG

?

The regex will work only if you have spaces around it.

  • 2 weeks later...
Posted

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

Posted

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...