${my-string} "Fête : Anniversaire
地點:巴黎
日期 : 08/12/2021
大獎 : texte"
我需要從此文本中提取日期,但我無法使用機器人框架得到解決方案,我嘗試過:
${REGULAR EXPRESSION} \d{2}\/\d{2}\/\d{4}
Get Regexp Matches ${my-string} ${REGULAR EXPRESSION}
但它給了我 null 結果,請問有什么解決方案嗎?
uj5u.com熱心網友回復:
我認為因為在 Python/Robot Framework 中,反斜杠被視為轉義字符,所以在您在 reg ex 中使用它的每個場合都需要一個額外的反斜杠
例如\\d{2}\\/\\d{2}\\/\\d{4}
所以這樣的事情應該有效:
*** 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}
帶輸出:
08/12/2021
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/425775.html
