Sign in to follow this  
Followers 0
MePHiTiC

Can't figure out how to use StringRegExp

12 posts in this topic

#1 ·  Posted (edited)

I'm reading data from a card swipe which returns the following data:

%FIRST_NAME^TEN_DIGIT_NUMBER^1^1^2F?

I'm trying to use StringRegExp to return just the TEN_DIGIT_NUMBER part of this. The FIRST_NAME field will vary in size depending on the name of the person. the %, ^, and ? characters remain the same on all cards. What expression would I use to display the TEN_DIGIT_NUMBER field?

Thanks for the help ... This has been killing me :S

MePH

Edited by MePHiTiC

Share this post


Link to post
Share on other sites



"\^\(\d{10})\^"


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.

Share this post


Link to post
Share on other sites

$string = '%FIRST_NAME^TEN_DIGIT_NUMBER^1^1^2F?'

$pattern = '\^(.*?)\^' ;pattern

$test = StringRegExp($string,$pattern, 3) ;funktion

MsgBox(0, "bla", $test[0])


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

Thanks for the replies ... I've tried both and got errors with both ... Currently this is what I have:

#include <CommMG.au3>

HotKeySet("{F4}", "Terminate")

$sErr = 1
_CommSetport(1,$sErr,9600,8,0,1,0)

While 1

$String =  _CommGetline(@CR,200,200)
$Pattern = '\^(.*?)\^'
$Test = StringRegExp($String,$Pattern,3)
If $String <> '' Then
    MsgBox(0,"",$Test[0])
EndIf

WEnd

Func Terminate()
    _Commcloseport()
    Exit 0
EndFunc

I'm getting Subscript used with non-Array variable. at $Test[0]

MePH

Share this post


Link to post
Share on other sites

Thanks for the replies ... I've tried both and got errors with both ... Currently this is what I have:

#include <CommMG.au3>

HotKeySet("{F4}", "Terminate")

$sErr = 1
_CommSetport(1,$sErr,9600,8,0,1,0)

While 1

$String =  _CommGetline(@CR,200,200)
$Pattern = '\^(.*?)\^'
$Test = StringRegExp($String,$Pattern,3)
If $String <> '' Then
    MsgBox(0,"",$Test[0])
EndIf

WEnd

Func Terminate()
    _Commcloseport()
    Exit 0
EndFunc

I'm getting Subscript used with non-Array variable. at $Test[0]

MePH

Now the only question is are you sure the output is as you say:
#include <array.au3>
Local $sString = "%Joe Blo^0123456789^1^1^2F?"
Local $aSRE = StringRegExp($sString, "\^(\d{10})\^", 3)
_ArrayDisplay($aSRE)
Works fine. xenobiologists code will pull the other data (ie... 1, 1) as well, when you asked for the 10 digit code you need to let the RegExp engine know it's something specific such as \d{10}

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.

Share this post


Link to post
Share on other sites

Works fine for me....

$String = '%FIRST_NAME^0123456789^1^1^2F?'
$Pattern = '\^(.*?)\^'
$Test = StringRegExp($String,$Pattern,3)
If $String <> '' Then
    MsgBox(0,"",$Test[0])
EndIf

Share this post


Link to post
Share on other sites

Works fine for me....

$String = '%FIRST_NAME^0123456789^1^1^2F?'
$Pattern = '\^(.*?)\^'
$Test = StringRegExp($String,$Pattern,3)
If $String <> '' Then
    MsgBox(0,"",$Test[0])
EndIf
You're only testing [0] but pulling all the matches (ie 3rd param = 3) in your test :)

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.

Share this post


Link to post
Share on other sites

You're only testing [0] but pulling all the matches (ie 3rd param = 3) in your test :)

Here is what the OP asked for.

I'm trying to use StringRegExp to return just the TEN_DIGIT_NUMBER part of this.

That script puts out 0123456789.

Share this post


Link to post
Share on other sites

Hi,

if you know there is only one 10 digits number then you can strip it down to:

#include <Array.au3>
$string = '%FIRST_NAME^1234567890^1^1^2F?'

$pattern = '\d{10}';pattern 
$test = StringRegExp($string,$pattern, 3);funktion
MsgBox(0, "bla", $test[0])
_ArrayDisplay($test)

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

#10 ·  Posted

Here is what the OP asked for.

That script puts out 0123456789.

I understand what the OP asked for, but as I said, you are only checking the first instance but telling the RegExp engine to check every instance.

If the OP has more than one instance of 10 digits, then you are not going to pull the correct information with your posted RegExp period.

[0] will equal 10 digit wanted

[1] will equal 1

[2] will equal 10 digit wanted

[3] will equal 1

etc...

Which certainly isn't the desired output.

Now, if the OP is only testing 1 string, and looking for 1 output, your code is still syntactically incorrect.

It would be: StringRegExp(string, pattern, 1)

Hi,

if you know there is only one 10 digits number then you can strip it down to:

#include <Array.au3>
$string = '%FIRST_NAME^1234567890^1^1^2F?'

$pattern = '\d{10}';pattern 
$test = StringRegExp($string,$pattern, 3);funktion
MsgBox(0, "bla", $test[0])
_ArrayDisplay($test)

Mega

Looks familiar: http://www.autoitscript.com/forum/index.ph...st&p=518231

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.

Share this post


Link to post
Share on other sites

#11 ·  Posted

Yes,

all I wanted to point out is, if you know there will be only one 10 digits number in the string, you can ignore the \^ at start and end.

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

#12 ·  Posted

Thanks for everyone's help and support ... I finally got it to work and below is the code:

#include <CommMG.au3>
HotKeySet("{F4}", "Terminate")

$sErr = 1
_CommSetport(1,$sErr,9600,8,0,1,0)
_CommGetLine(@CR,0, 0)

While 1
    $string = _CommGetLine(@CR,0,0)
    $pattern = '\d{10}';pattern
    $test = StringRegExp($string,$pattern, 3)
    MsgBox(0, "", $test[0])
WEnd

Func Terminate()
    _Commcloseport()
    Exit 0
EndFunc

Thanks!

MePH

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