GordonFreeman Posted March 30, 2019 Share Posted March 30, 2019 (edited) Hi guys, i'm trying to match an string first than another. In this case regex should match ZA if ZA exists and after match Z if exists. But getting unexpected results getting A in the second scenario In other words the first part of regex should try match first ZA, WA or VA and if not match one then try Z,W or V Other logic point view of same problem is match Z or W or V with A and if not match one of these, match one alone #include <StringConstants.au3> #include <Array.au3> $pattern = '([ZA,WA,VA,Z,W,V])([0-9]{1,3})(?:[-])([0-9]{1,3})([y,Y]{0,1})' ; Possible scenario 1: Works as expected ( Row 1 equal Z) $s1 = 'Z01-02y' ; Possible scenario 2: Not works as expects (Row 1 should be ZA instead of A) $s2 = 'ZA01-02Y' $as1 = StringRegExp($s1, $pattern, $STR_REGEXPARRAYFULLMATCH) _ArrayDisplay($as1) $as2 = StringRegExp($s2, $pattern, $STR_REGEXPARRAYFULLMATCH) _ArrayDisplay($as2) ; Other example scenarios ;W881-12Y (Row 1 should be W) ;WA02-921 (Row 1 should be WA) ; Most part is working nice, the only problem relies on the first part of regex thanks in advance for any efforts Edited March 30, 2019 by GordonFreeman Frabjous Installation Link to comment Share on other sites More sharing options...
Bowmore Posted March 30, 2019 Share Posted March 30, 2019 This pattern will give you the correct result if I have understood your requirement correctly $pattern = '(ZA|WA|VA|Z|W|V)([0-9]{1,3})(?:[-])([0-9]{1,3})([y,Y]{0,1})' GordonFreeman 1 "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
GordonFreeman Posted March 30, 2019 Author Share Posted March 30, 2019 18 minutes ago, Bowmore said: This pattern will give you the correct result if I have understood your requirement correctly $pattern = '(ZA|WA|VA|Z|W|V)([0-9]{1,3})(?:[-])([0-9]{1,3})([y,Y]{0,1})' Thanks its exactly i need Frabjous Installation Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted March 30, 2019 Share Posted March 30, 2019 (edited) @GordonFreeman You could try this one too: (?i)^((?:V|W|Z)A?)(\d{1,3})\-(\d{1,3})(Y)?$ Edited March 30, 2019 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette 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