${my-string} "Fête : Anniversaire
Emplacement : Paris
Date : 08/12/2021
Prix : texte"
I need to extract the date from this text but i can't end up with a solution using robot framework , i tried :
${REGULAR EXPRESSION} \d{2}\/\d{2}\/\d{4}
Get Regexp Matches ${my-string} ${REGULAR EXPRESSION}
But it gave me null as a result , any solution for that please ?
CodePudding user response:
I think because in Python/Robot Framework the backslash is treated as am escape character, you need an additional backslash on each occassion you use it in your reg ex
e.g. \\d{2}\\/\\d{2}\\/\\d{4}
So something like this should work:
*** Settings ***
Library String
*** Test Cases ***
Check Date Regex
${date} Set Variable Fête : Anniversaire Emplacement : Paris Date : 08/12/2021 Prix : texte
${regex} Set Variable \\d{2}\\/\\d{2}\\/\\d{4}
${matches} Get Regexp Matches ${date} ${regex}
${match} Set Variable ${NONE}
IF ${matches}
${match} Set Variable ${matches}[0]
END
log to console ${match}
With output:
08/12/2021