Jump to content

Extract data from StringSplit Array via StringRegExp


TeTube
 Share

Recommended Posts

Hello people,

I wrote some AutoIT script to parse all Strings from a html page into an array.

After this, I want to extract strings out of the big string array via StringRegExp.

Code:

$oIE is my internet explorer handle where to parse the data from

$aBodyText is the array where all strings are parsed in.

$aProfileNames is the array where the extracted strings should be stored in.

While 1

$aBodyText = StringSplit(_IEBodyReadText($oIE), "", 1)

If @error = 0 Then ExitLoop

TrayTip("Error_Readnames:", "While doing StringSplit", 10)

Sleep (10000)

WEnd

While 1

;- String Pattern: "w (0-9)(0-9) Profilename"

$aProfileNames = StringRegExp($aBodyText[2], " w \d\d (.*)", 3)

If @error = 0 Then ExitLoop

TrayTip("Error_Readnames:", "While doing StringRegExp", 10)

Sleep (10000)

WEnd

Here is an example of the extracted html body:

http://pastebin.com/UBTvpMac

The data I would like to extract starts in 1822. and appears always as w DIGITDIGIT XXXXXXXXXXXXXXX

Somehow, when I run this, I get an error in the regular expression part.

Edited by TeTube
Link to comment
Share on other sites

  • Moderators

TeTube,

Welcome to the AutoIt forum. :graduated:

That way of giving us data is not a lot of use - much better to post a string. :)

I think this is what you want, based on what I think is the data I could extract from the dump you linked to:

#include <Array.au3>

$sText = "Login vor 13 Min.w 16 its_adel 12 BerlinLogin vor 1 Std.w 16 _Paattie 13"

$aMatches = StringRegExp($sText, "(?i)(?U)w\x20\d\d\x20(.*)\x20", 3)

_ArrayDisplay($aMatches)

Note I used the \xDD format to define a space and not a literal {SPACE}. ;)

SRE Explanation:

(?i)          - Case insensitive (in case you find a W)
(?U)          - look for the smallest matches (try it without this and see what you get!)
w\x20\d\d\x20 - look for "w " followed by 2 digits and then another " "
(.*)          - capture everything up until
\x20          - the next " "

Does it work for you? If not post a string holding the data so we can work with it more easily. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thanks for the fast reply.

Well, this is exactly what I was looking for.

The strings gonna look like: "w 21 OmgItsMe spoagdnoisdg owegpsogaüpgüsgrjopwog päpgnwpejgpweg w 18 YeahItsme sigosgnsdpgnsogn afoknsog oafodsigosö oghs w 18 soPro "

But actually I m no sure if I can just pass the whole string array from the stringsplit function into the StringRegExp?

Like I have a working regular expression, but the data I parse isnt working? °_°

Edited by TeTube
Link to comment
Share on other sites

  • Moderators

TeTube,

I m no sure if I can just pass the whole string array from the stringsplit function into the StringRegExp

There is no need to use StringSplit at all - just pass the whole string into the SRE as I did above. ;)

Sorry, I should have told you specifically, but I thought the example code was clear enough. SREs work (as their name suggests :)) on strings, not arrays. :graduated:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Again, thanks :graduated:

I just parsed the HTML body directly into the SRE.

In each Step, I add the extracted Data into a global array.

After, it parsed all the data I wanted into a global array, this steps appears tto be correct (_ArrayDisplay showed me in the end a correct array)

But now, the rest of my program doesnt work anymore (the parts which use the global array) xD?

Could it be the parsed string via SRE changed?

Edited by TeTube
Link to comment
Share on other sites

  • Moderators

TeTube,

There is nothing to stop you using StringSplit to create an array to use in the rest of your script - you just do not need it for the SRE part. :graduated:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...