Jump to content

StringRegExp match bigger string first than smaller


Recommended Posts

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 by GordonFreeman
Link to comment
Share on other sites

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})'

 

"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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...