Jump to content
X70

Need help with expression checking

Recommended Posts

Hi, i'm new to AutoIT scripting. I have a basic question,
I want to verify partial of the output and I'm not sure how to this. For example:
Output = B1234567890
Need to verify: B12345

Appreciate any of your help

Share this post


Link to post
Share on other sites
1 hour ago, Subz said:

Try https://regexr.com/ for example you could use something like:

^([A-Z][0-9]{5,5})

 

Thanks Subz but could you please elaborate more on the function? I'm quite new to this

Share this post


Link to post
Share on other sites
Posted (edited)
1 hour ago, X70 said:

... but could you please elaborate more on the function? I'm quite new to this

It depends on what you are looking for :

; Output         = B1234567890
; Need to verify : B12345

Global $sOutput, $sMatch, $bVerified
$sOutput = "B1234567890"
$sMatch  = "B12345"

; Example 1. Check : Output starts with a letter (A..Z) followed by 5 numbers(0..9)
$bVerified = StringRegExp($sOutput, "(?i)^([A-Z])\d{5}")
If $bVerified Then
    ConsoleWrite("+ EX 1. ==> Verified" & @CRLF)
Else
    ConsoleWrite("! EX 1. ==> Not Verified" & @CRLF)
Endif

; Example 2. The first 6 characters must match exactly :
$bVerified = StringRegExp($sOutput, "(?i)^" & $sMatch)
If $bVerified Then
    ConsoleWrite("+ EX 2. ==> Verified" & @CRLF)
Else
    ConsoleWrite("! EX 2. ==> Not Verified" & @CRLF)
Endif

; Example 2.1. : for exact match, you could also use StringLeft()
If StringLeft($sOutput, 6) = $sMatch Then
    ConsoleWrite("+ EX 2.1. ==> Verified" & @CRLF)
Else
    ConsoleWrite("! EX 2.1. ==> Not Verified" & @CRLF)
Endif

 

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...