EasyPatterns Not so easy

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

EasyPatterns Not so easy

Post by mightycpa » Thu Mar 04, 2021 10:18 pm

for me...

Consider the following code:

Code: Select all

  //start with 4 or 5 digit alphanumeric string
  //verify pattern: letter digit letter digit optional letter 
  //where first 2 letters are A-H only, 
  //digits are 0-9
  //optional letter is blank or R,K,B,Q only
  
  Let>v_cmd=A4C2L
  MidStr>v_cmd,1,5,vcmd
  MidStr>vcmd,1,1,vcmd1
  MidStr>vcmd,2,1,vcmd2
  MidStr>vcmd,3,1,vcmd3
  MidStr>vcmd,4,1,vcmd4
  MidStr>vcmd,5,1,vcmd5
  Let>v_pattern_a=[<ABCDEFGH>]
  Let>v_pattern_d=[digit]
  Let>v_pattern_5=[<RKBQ>]
  RegEx>v_pattern_a,vcmd1,0,vm1,vmcnt1,0
  RegEx>v_pattern_d,vcmd2,0,vm2,vmcnt2,0
  RegEx>v_pattern_a,vcmd3,0,vm3,vmcnt3,0
  RegEx>v_pattern_d,vcmd4,0,vm4,vmcnt4,0
  RegEx>v_pattern_5,vcmd5,0,vm5,vmcnt5,0
  Let>v_chk1={%vmcnt1%+%vmcnt2%+%vmcnt3%+%vmcnt4%}
  If>v_chk1=4
    If>vmcnt5=1
      //v_cmd is fine
    Else
      MidStr>v_cmd,1,4,v_cmd
    Endif
  Else
    Let>v_cmd=Nothing Passed
  Endif
  MessageModal>v_cmd

The above doesn't work because the letters work, but the digits don't. I can't see why.

In addition to that, this should be do-able in one pattern, shouldn't it? Again, I'm stymied.

Any help would be appreciated.
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Re: EasyPatterns Not so easy

Post by Bob Hansen » Fri Mar 05, 2021 2:50 am

I found your description a bit confusing, but I think understand it. I came up with some code that should look something like this:

Code: Select all

Let>VAREXPLICIT=0
Let>Pattern=[A-H][0-9][A-H][0-9][RKBQ]?
Let>Source=A4C2L57LN8KG7D6B76GF
RegEx>Pattern,Source,0,Match,Count,0,,
MessageModal>Found %Count% matches%CRLF%First match is: %Match_1%%CRLF%Second match is: %Match_2%
I don't have access to my program right now, so this is done untested, from memory. May be one or more typos, but hopefully close enough to help you. Good luck.
Last edited by Bob Hansen on Fri Mar 05, 2021 4:04 pm, edited 1 time in total.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

hagchr
Automation Wizard
Posts: 327
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: EasyPatterns Not so easy

Post by hagchr » Fri Mar 05, 2021 10:40 am

For EasyPattern you need to set the third parameter to 1, ie. RegEx>...,...,1,...

Bob's suggestion works as well, you may need to add a space char in the last bracket if that should be allowed as optional.

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Re: EasyPatterns Not so easy

Post by mightycpa » Fri Mar 05, 2021 3:44 pm

Thanks both. I can only have 4 or 5 chars, I would consider 6 invalid. That's easy enough to figure out. I think the word "digits" threw me, I thought it was just like a real-world pattern. The A-H makes sense.

I ended up having to treat the two cases (first four characters, optional fifth) separately. Blank works, but NULL does not. There may be a way to do it, but Bob's suggestion gives me some better understanding.

1 in the third parameter threw an error that I didn't understand at first. I take it that Bob's method is real regex and not Easy Pattern.

Anyway, it works. Thanks again.
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Re: EasyPatterns Not so easy

Post by Bob Hansen » Fri Mar 05, 2021 4:29 pm

I did have a typo, but have modified the code in my reply above.
From: Let>Pattern=[A-H][0-9][A-H][0-9][RKBQ]*
To: Let>Pattern=[A-H][0-9][A-H][0-9]][RKBQ]?

The last character of the RegEx should have been a "?" instead of "*".
The * would have captured multiple instances of the last character.
The ? only captures one or none, so no need to put in a space character after the last class.

And YES, you can use some word classes.
You can use [[:digit:]] vs. [0-9]. Note the extra brackets.

So, a final example with the correction, and both digit options would look like this:

Code: Select all

Let>Pattern=[A-H][[:digit:]][A-H][0-9][RKBQ]?
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Re: EasyPatterns Not so easy

Post by mightycpa » Fri Mar 05, 2021 5:08 pm

I appreciate the lesson! Thanks
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

User avatar
PepsiHog
Automation Wizard
Posts: 511
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Re: EasyPatterns Not so easy

Post by PepsiHog » Wed Mar 10, 2021 5:03 pm

LOL! I jump into helping without looking! Oops. But it's the thought that counts. Right?


Hello mightycpa,

You just misinterpreted the RegEx. A few corrections, and it works.

Code: Select all

  //start with 4 or 5 digit alphanumeric string
  //verify pattern: letter digit letter digit optional letter 
  //where first 2 letters are A-H only, 
  //digits are 0-9
  //optional letter is blank or R,K,B,Q only
  
  Let>v_cmd=A4C2L
  MidStr>v_cmd,1,5,vcmd
  MidStr>vcmd,1,1,vcmd1
  MidStr>vcmd,2,1,vcmd2
  MidStr>vcmd,3,1,vcmd3
  MidStr>vcmd,4,1,vcmd4
  MidStr>vcmd,5,1,vcmd5
  Let>v_pattern_a=[A-H]
  Let>v_pattern_d=\d
  Let>v_pattern_5=[RKBQ]
  RegEx>v_pattern_a,vcmd1,0,vm1,vmcnt1,0
  RegEx>v_pattern_d,vcmd2,0,vm2,vmcnt2,0
  RegEx>v_pattern_a,vcmd3,0,vm3,vmcnt3,0
  RegEx>v_pattern_d,vcmd4,0,vm4,vmcnt4,0
  RegEx>v_pattern_5,vcmd5,0,vm5,vmcnt5,0
  
  Let>v_chk1={%vmcnt1%+%vmcnt2%+%vmcnt3%+%vmcnt4%}
  If>v_chk1=4
    If>vmcnt5=1
      mdl>v_cmd is fine
    Else
      MidStr>v_cmd,1,4,v_cmd
    Endif
  Else
    Let>v_cmd=Nothing Passed
  Endif
  MessageModal>v_cmd

Good Luck,
PepsiHog


@Bob,
Yours is better. Cool.
Last edited by PepsiHog on Wed Mar 10, 2021 5:10 pm, edited 1 time in total.
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2021) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Re: EasyPatterns Not so easy

Post by mightycpa » Wed Mar 10, 2021 5:09 pm

Image Thanks!
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts