MePHiTiC Posted May 8, 2008 Share Posted May 8, 2008 (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 :SMePH Edited May 8, 2008 by MePHiTiC Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 8, 2008 Moderators Share Posted May 8, 2008 "\^\(\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. Link to comment Share on other sites More sharing options...
Xenobiologist Posted May 8, 2008 Share Posted May 8, 2008 $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 Link to comment Share on other sites More sharing options...
MePHiTiC Posted May 8, 2008 Author Share Posted May 8, 2008 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 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 8, 2008 Moderators Share Posted May 8, 2008 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] MePHNow 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. Link to comment Share on other sites More sharing options...
weaponx Posted May 8, 2008 Share Posted May 8, 2008 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 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 8, 2008 Moderators Share Posted May 8, 2008 Works fine for me.... $String = '%FIRST_NAME^0123456789^1^1^2F?' $Pattern = '\^(.*?)\^' $Test = StringRegExp($String,$Pattern,3) If $String <> '' Then MsgBox(0,"",$Test[0]) EndIfYou'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. Link to comment Share on other sites More sharing options...
weaponx Posted May 8, 2008 Share Posted May 8, 2008 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. Link to comment Share on other sites More sharing options...
Xenobiologist Posted May 8, 2008 Share Posted May 8, 2008 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 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 8, 2008 Moderators Share Posted May 8, 2008 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. Link to comment Share on other sites More sharing options...
Xenobiologist Posted May 9, 2008 Share Posted May 9, 2008 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 Link to comment Share on other sites More sharing options...
MePHiTiC Posted May 9, 2008 Author Share Posted May 9, 2008 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now