RegEX - Find Magnetic Card String for Track 1 and Track 2 substringsHow to check if a string contains a substring in BashHow to check whether a string contains a substring in JavaScript?In Java, how do I check if a string contains a substring (ignoring case)?Does Python have a string 'contains' substring method?How do I check if string contains substring?Where can I find magnetic strip (track) test data?How to getting started with magnetic stripe cards?Reading and writing magnetic card reader input with PythonHow to read a magnetic card in androidMSR605 Magnetic Card Reader unable to read cards without special software

How to align and center standalone amsmath equations?

Can the Supreme Court overturn an impeachment?

Is camera lens focus an exact point or a range?

Proving a function is onto where f(x)=|x|.

Open a doc from terminal, but not by its name

THT: What is a squared annular “ring”?

Bob has never been a M before

Why is Arduino resetting while driving motors?

Do the concepts of IP address and network interface not belong to the same layer?

Drawing a topological "handle" with Tikz

Reply 'no position' while the job posting is still there

Varistor? Purpose and principle

Why did the EU agree to delay the Brexit deadline?

Journal losing indexing services

Two-sided logarithm inequality

Why did the HMS Bounty go back to a time when whales are already rare?

Divine apple island

Flux received by a negative charge

What major Native American tribes were around Santa Fe during the late 1850s?

What does this horizontal bar at the first measure mean?

Freedom of speech and where it applies

Database accidentally deleted with a bash script

A Permanent Norse Presence in America

Could solar power be utilized and substitute coal in the 19th Century



RegEX - Find Magnetic Card String for Track 1 and Track 2 substrings


How to check if a string contains a substring in BashHow to check whether a string contains a substring in JavaScript?In Java, how do I check if a string contains a substring (ignoring case)?Does Python have a string 'contains' substring method?How do I check if string contains substring?Where can I find magnetic strip (track) test data?How to getting started with magnetic stripe cards?Reading and writing magnetic card reader input with PythonHow to read a magnetic card in androidMSR605 Magnetic Card Reader unable to read cards without special software













0















A Card reader is simply a keyboard input that once a Card is swiped, a string is displayed in any focused text field.



I would like to split the following:



Track 1: which is delimited by a % and a ?



Track 2: which is delimited by a ; and a ?



However not all Cards have both Tracks, some have only the first, and some have only the second.



I'd like to find a RegEx that parses out Track 1 and Track 2 if either exist.



Here are sample Cards swipes which generates these Strings:



%12345?;54321? (has both Track 1 & Track 2)
%1234678? (has only Track 1)
;98765? (has only Track 2)
%93857563932746584?;38475? (has both Track 1 & Track 2)


This is the example I'm building off of:



%([0-9]+)?) // for first Track
;([0-9]+)?) // for second Track









share|improve this question
























  • While you wait to find the RegEx... For such simple strings, why not just use substr and/or substring together with firstIndexOf(x) or lastIndexOf(x) where the x could be the %or ? or ;... Also if your "tracks" are numerical why not extract by splitting at & then also removing special characters (leaves tracks)?

    – VC.One
    Mar 21 at 14:45











  • PS: I think you got down-voted because your programming question has neither RegEx nor AS3 codes. Show your best try with this regEx and maybe someone can fix it.

    – VC.One
    Mar 21 at 14:48











  • I did use finding by Index the delimeters, and substring-ing the indexes, however it did not work for all my use cases.

    – Yozef
    Mar 21 at 20:52















0















A Card reader is simply a keyboard input that once a Card is swiped, a string is displayed in any focused text field.



I would like to split the following:



Track 1: which is delimited by a % and a ?



Track 2: which is delimited by a ; and a ?



However not all Cards have both Tracks, some have only the first, and some have only the second.



I'd like to find a RegEx that parses out Track 1 and Track 2 if either exist.



Here are sample Cards swipes which generates these Strings:



%12345?;54321? (has both Track 1 & Track 2)
%1234678? (has only Track 1)
;98765? (has only Track 2)
%93857563932746584?;38475? (has both Track 1 & Track 2)


This is the example I'm building off of:



%([0-9]+)?) // for first Track
;([0-9]+)?) // for second Track









share|improve this question
























  • While you wait to find the RegEx... For such simple strings, why not just use substr and/or substring together with firstIndexOf(x) or lastIndexOf(x) where the x could be the %or ? or ;... Also if your "tracks" are numerical why not extract by splitting at & then also removing special characters (leaves tracks)?

    – VC.One
    Mar 21 at 14:45











  • PS: I think you got down-voted because your programming question has neither RegEx nor AS3 codes. Show your best try with this regEx and maybe someone can fix it.

    – VC.One
    Mar 21 at 14:48











  • I did use finding by Index the delimeters, and substring-ing the indexes, however it did not work for all my use cases.

    – Yozef
    Mar 21 at 20:52













0












0








0


0






A Card reader is simply a keyboard input that once a Card is swiped, a string is displayed in any focused text field.



I would like to split the following:



Track 1: which is delimited by a % and a ?



Track 2: which is delimited by a ; and a ?



However not all Cards have both Tracks, some have only the first, and some have only the second.



I'd like to find a RegEx that parses out Track 1 and Track 2 if either exist.



Here are sample Cards swipes which generates these Strings:



%12345?;54321? (has both Track 1 & Track 2)
%1234678? (has only Track 1)
;98765? (has only Track 2)
%93857563932746584?;38475? (has both Track 1 & Track 2)


This is the example I'm building off of:



%([0-9]+)?) // for first Track
;([0-9]+)?) // for second Track









share|improve this question
















A Card reader is simply a keyboard input that once a Card is swiped, a string is displayed in any focused text field.



I would like to split the following:



Track 1: which is delimited by a % and a ?



Track 2: which is delimited by a ; and a ?



However not all Cards have both Tracks, some have only the first, and some have only the second.



I'd like to find a RegEx that parses out Track 1 and Track 2 if either exist.



Here are sample Cards swipes which generates these Strings:



%12345?;54321? (has both Track 1 & Track 2)
%1234678? (has only Track 1)
;98765? (has only Track 2)
%93857563932746584?;38475? (has both Track 1 & Track 2)


This is the example I'm building off of:



%([0-9]+)?) // for first Track
;([0-9]+)?) // for second Track






regex actionscript-3 substring magnetic-cards






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago







Yozef

















asked Mar 21 at 13:49









YozefYozef

7971027




7971027












  • While you wait to find the RegEx... For such simple strings, why not just use substr and/or substring together with firstIndexOf(x) or lastIndexOf(x) where the x could be the %or ? or ;... Also if your "tracks" are numerical why not extract by splitting at & then also removing special characters (leaves tracks)?

    – VC.One
    Mar 21 at 14:45











  • PS: I think you got down-voted because your programming question has neither RegEx nor AS3 codes. Show your best try with this regEx and maybe someone can fix it.

    – VC.One
    Mar 21 at 14:48











  • I did use finding by Index the delimeters, and substring-ing the indexes, however it did not work for all my use cases.

    – Yozef
    Mar 21 at 20:52

















  • While you wait to find the RegEx... For such simple strings, why not just use substr and/or substring together with firstIndexOf(x) or lastIndexOf(x) where the x could be the %or ? or ;... Also if your "tracks" are numerical why not extract by splitting at & then also removing special characters (leaves tracks)?

    – VC.One
    Mar 21 at 14:45











  • PS: I think you got down-voted because your programming question has neither RegEx nor AS3 codes. Show your best try with this regEx and maybe someone can fix it.

    – VC.One
    Mar 21 at 14:48











  • I did use finding by Index the delimeters, and substring-ing the indexes, however it did not work for all my use cases.

    – Yozef
    Mar 21 at 20:52
















While you wait to find the RegEx... For such simple strings, why not just use substr and/or substring together with firstIndexOf(x) or lastIndexOf(x) where the x could be the %or ? or ;... Also if your "tracks" are numerical why not extract by splitting at & then also removing special characters (leaves tracks)?

– VC.One
Mar 21 at 14:45





While you wait to find the RegEx... For such simple strings, why not just use substr and/or substring together with firstIndexOf(x) or lastIndexOf(x) where the x could be the %or ? or ;... Also if your "tracks" are numerical why not extract by splitting at & then also removing special characters (leaves tracks)?

– VC.One
Mar 21 at 14:45













PS: I think you got down-voted because your programming question has neither RegEx nor AS3 codes. Show your best try with this regEx and maybe someone can fix it.

– VC.One
Mar 21 at 14:48





PS: I think you got down-voted because your programming question has neither RegEx nor AS3 codes. Show your best try with this regEx and maybe someone can fix it.

– VC.One
Mar 21 at 14:48













I did use finding by Index the delimeters, and substring-ing the indexes, however it did not work for all my use cases.

– Yozef
Mar 21 at 20:52





I did use finding by Index the delimeters, and substring-ing the indexes, however it did not work for all my use cases.

– Yozef
Mar 21 at 20:52












1 Answer
1






active

oldest

votes


















2














This regex will match your track groupings:



/(?:%([0-9]+)?)?(?:;([0-9]+)?)?/g

(?: // non-capturing group
% // match the % character
( // capturing group for the first number
[0-9] // match digits; could also use d
+ // match 1 or more digits
) // close the group
? // match the ? character
)
? // match 0 or 1 of the non-capturing group
(?:
; // match the ; character
[0-9]
+
)
?
)
?


BTW, I used regexr to figure out the regex patterns here (free site, no affiliation).






share|improve this answer























  • @Yozef On the Replace tab, try this expression: << $1 - $2 >>

    – Brian
    Mar 21 at 21:13











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281952%2fregex-find-magnetic-card-string-for-track-1-and-track-2-substrings%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














This regex will match your track groupings:



/(?:%([0-9]+)?)?(?:;([0-9]+)?)?/g

(?: // non-capturing group
% // match the % character
( // capturing group for the first number
[0-9] // match digits; could also use d
+ // match 1 or more digits
) // close the group
? // match the ? character
)
? // match 0 or 1 of the non-capturing group
(?:
; // match the ; character
[0-9]
+
)
?
)
?


BTW, I used regexr to figure out the regex patterns here (free site, no affiliation).






share|improve this answer























  • @Yozef On the Replace tab, try this expression: << $1 - $2 >>

    – Brian
    Mar 21 at 21:13
















2














This regex will match your track groupings:



/(?:%([0-9]+)?)?(?:;([0-9]+)?)?/g

(?: // non-capturing group
% // match the % character
( // capturing group for the first number
[0-9] // match digits; could also use d
+ // match 1 or more digits
) // close the group
? // match the ? character
)
? // match 0 or 1 of the non-capturing group
(?:
; // match the ; character
[0-9]
+
)
?
)
?


BTW, I used regexr to figure out the regex patterns here (free site, no affiliation).






share|improve this answer























  • @Yozef On the Replace tab, try this expression: << $1 - $2 >>

    – Brian
    Mar 21 at 21:13














2












2








2







This regex will match your track groupings:



/(?:%([0-9]+)?)?(?:;([0-9]+)?)?/g

(?: // non-capturing group
% // match the % character
( // capturing group for the first number
[0-9] // match digits; could also use d
+ // match 1 or more digits
) // close the group
? // match the ? character
)
? // match 0 or 1 of the non-capturing group
(?:
; // match the ; character
[0-9]
+
)
?
)
?


BTW, I used regexr to figure out the regex patterns here (free site, no affiliation).






share|improve this answer













This regex will match your track groupings:



/(?:%([0-9]+)?)?(?:;([0-9]+)?)?/g

(?: // non-capturing group
% // match the % character
( // capturing group for the first number
[0-9] // match digits; could also use d
+ // match 1 or more digits
) // close the group
? // match the ? character
)
? // match 0 or 1 of the non-capturing group
(?:
; // match the ; character
[0-9]
+
)
?
)
?


BTW, I used regexr to figure out the regex patterns here (free site, no affiliation).







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 21 at 15:56









BrianBrian

3,43731535




3,43731535












  • @Yozef On the Replace tab, try this expression: << $1 - $2 >>

    – Brian
    Mar 21 at 21:13


















  • @Yozef On the Replace tab, try this expression: << $1 - $2 >>

    – Brian
    Mar 21 at 21:13

















@Yozef On the Replace tab, try this expression: << $1 - $2 >>

– Brian
Mar 21 at 21:13






@Yozef On the Replace tab, try this expression: << $1 - $2 >>

– Brian
Mar 21 at 21:13




















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281952%2fregex-find-magnetic-card-string-for-track-1-and-track-2-substrings%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript