Sign in to follow this  
Followers 0
Oldschool

StringRegExp Help Please

7 posts in this topic

I'm trying to read of prices from lines that look like this:

Item Price [$16.96].#92378654906#

Dim $aRecords
If Not _FileReadToArray("text.txt",$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf

For $y = 1614 to $aRecords[0] 
    ;Msgbox(0,'Record:' & $x, $aRecords[$x])
    If StringInStr($aRecords[$y], "$") Then
        Local $price = StringRegExp($aRecords[$y],"(?i)e"&Chr(32)&Chr(91)&"$(.*)"&Chr(93), 0)
        MsgBox(0, "", $price, 1) ;<<===Item Price
        ;ExitLoop
    EndIf
Next

I get no error, MsgBox returns zero. It does not like the brackets [] I suppose.

How do I fix this please?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

it's not perfect, but should point you in the right direction.

Local $price = StringRegExp($aRecords[$y],"(.*[$.*])", 0)

Maybe someone with with better regex will give you better example

Edited by Kerros

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Share this post


Link to post
Share on other sites

it's not perfect, but should point you in the right direction.

Local $price = StringRegExp($aRecords[$y],"(.*[$.*])", 0)

Maybe someone with with better regex will give you better example

The above does not work..

If slightly modified it returns the whole string:

Local $price = StringRegExp($aRecords[$y],"(.*[$.*])", 3)
MsgBox(0, "", $price[0], 1)

I need to grab the digits only....

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Well this is going to return an array of everything after the $ upto the trailing bracket.

Local $price = StringRegExp($aRecords[$y],"(\$\d{1,}.\d{2,})", 3)

That should work. messy, but should work.

Edited by Kerros

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Share this post


Link to post
Share on other sites

Well this is going to return an array of everything after the $ upto the trailing bracket.

Local $price = StringRegExp($aRecords[$y],"(\$\d{1,}.\d{2,})", 3)

That should work. messy, but should work.

Thanks, I'll test it out in a sec...

I got it working with the StringSplit instead for now.

For $y = $aRecords[0] - 40 to $aRecords[0] 
    If StringInStr($aRecords[$y], "$") Then
        Local $var = StringSplit($aRecords[$y], Chr(91) & Chr(36), 1) 
        Local $var1 = StringSplit($var[2], Chr(93), 1)
                MsgBox(0, "", $var1[1])
    EndIf   
Next

Share this post


Link to post
Share on other sites

Hi,

(?<=\[\$)\d*\.\d*(?=\])

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Hi,

(?<=\[\$)\d*\.\d*(?=\])

So long,

Mega

That's an interesting approach... here's another:
#include <array.au3>
$sString = "Item Price [$16.96].#92378654906#"
$aSRE = StringRegExp($sString, "\[\$([\d,\.]+)\]", 3)
_ArrayDisplay($aSRE)

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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
Sign in to follow this  
Followers 0