TheDcoder

Help with splitting a complex string

14 posts in this topic

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


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites



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)

Share this post


Link to post
Share on other sites

@jchd Perfect! Thanks! :thumbsup:


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

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


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

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

 

1 person likes this

Share this post


Link to post
Share on other sites

@jguinch Thanks!

4 minutes ago, jguinch said:

your first message was not clear enough

Sorry! :sweating:

 

Is there a way to validate if a string is in that format?


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

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

 

1 person likes this

Share this post


Link to post
Share on other sites

:facepalm:

 

Thanks for your help! :thumbsup:


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Nope, The spaces are always there :)


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

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


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

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

1 person likes this

 

venezuela.png Would you like to say thank to Danyfirex using a warmy way?  offer me a cup of coffee... coffee.png

autoit_scripter_blue_userbar.png

       AutoIt...

 

 

Share this post


Link to post
Share on other sites

Purrrrfect! :D


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

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

  • Similar Content

    • TheAutomator
      By TheAutomator
      Can anyone tell me why this isn't working?..
      #include <array.au3> $regexp = StringRegExp("test 'a b c'", "'([^']|'')*'|\S+", 3) _ArrayDisplay($regexp) trying to split this "test 'a b c'  'some other '' test'' ...'" into:
      0: test
      1: 'a b c'
      2: ...
      but it gives me:
      0: test
      1: c
    • JustinZandee
      By JustinZandee
      I need a random string generator which creates 15 letters/numbers.
      How can I make that?
    • anthonyjr2
      By anthonyjr2
      Hi guys,
      I am pretty bad with regex, and am having some trouble trying to come up with an expression for a certain type of string. Basically I want to be able to tell if a string is of the format:
      AA#####A
      Where the A's are any letter from A-Z and the #'s are any digit from 0-9.
      I've been playing around with a regex tester online for a while but I can't really seem to grasp the concept very well. Could anyone give me any tips?
      This isn't exactly an AutoIt specific question which is why I didn't post it in General Help & Support.
    • LoneWolf_2106
      By LoneWolf_2106
      Hi everybody,
      i have a question related to strings items in an Array and sorting. Maybe someone can advice me how to solve the issue.
      I have an Array of strings, every item of the Array is as following:
      INFO [13.06.2017 11:48:01] [Thread-13] [ConGenImpUsb -> waitForConnection]  INFO [07.06.2017 08:55:44] [main] MDU5 - Ver 5.1x I want to sort the item in the array by date and time, is there any function which allows me to sort by date/time?
      Thanks in advance