How to set Boolean value based on outcome of Match Regexp

32 views
Skip to first unread message

Tonger Core

unread,
Nov 23, 2022, 8:45:16 AM11/23/22
to robotframework-users
Hi Everyone, I want to evaluate the value in a variable through regular expression. When the variable does not match the reg expression I want to perform a certain keyword.I have

*** Variables ***
${geb-dat}= 1974-06-01

*** Test Cases ***
Bepaal juiste datum formaat
   ${a}= Should Match Regexp ${geb-dat} ^[0-9]{2}-[0-9]{4}-[0-9]{2}
   Log ${a}
   IF ${a} == 'false'
         Format Dateformat ${geb-dat}
  ELSE
        Log something
  END

So in case the reg expression is not a match I want it to perform keyword "Format DateFormat"

I am getting the errormessage:
'1974-06-01' does not match '^[0-9]{2}-[0-9]{4}-[0-9]{2}'

I want it to result in boolean true or false. So I can eveluate that in my IF ELSE statement.

How to do that?

Kind Regards, Marco

Craig Despeaux

unread,
Nov 23, 2022, 10:25:58 AM11/23/22
to robotframework-users
Use this:

${a}  Run Keyword And Return Status  Should Match Regexp ${geb-dat} ^[0-9]{2}-[0-9]{4}-[0-9]{2}

Your IF condition also needs to reference ${False} rather than false as a string.

Craig

Reply all
Reply to author
Forward
0 new messages