【发布时间】:2021-05-07 07:44:09
【问题描述】:
我想在 Robot 框架测试中包含一个字符串 RegEx 匹配。 在THIS 链接中有工作的正则表达式
这是我的机器人框架脚本代码:
*** Settings ***
Library String
Library Collections
Library OperatingSystem
Library DateTime
*** Test Cases ***
RegTest
${result}= Set Variable https://www.instagram.com/test.profile/
${lines} = Get Lines Matching Regexp ${result} Reg\\"(?:https?:)?\/\/(?:www\.)?(?:instagram\.com|instagr\.am)\/(?P<username>[A-Za-z0-9_](?:(?:[A-Za-z0-9_]|(?:\.(?!\.))){0,28}(?:[A-Za-z0-9_]))?)"im
Log ${lines}
所以即使 RegEx 证明有效,基本上也没有匹配项。 试图查看 RoboFramework 文档HERE,但我无法弄清楚我做错了什么。 我错过了语法中的某些内容吗? 谢谢
###更新 Robotframework 正则表达式语法(来自文档):
${lines} = Get Lines Matching Regexp ${result} Reg\\w{3} example
【问题讨论】:
-
看起来应该是
Reg "^(?:https?://)?(?:www\\.)?(?:instagr(?:\\.am|am\\.com))/([\\w.-]+)/$" -
您是否要匹配以五个字节
Reg\"开头的字符串? -
没有 @BryanOakley 只是想符合和理解 RoboFramework 正则表达式语法,我还在上面的问题中更新了一个摘录
-
@WiktorStribiżew 尝试 y 语法不起作用
-
好吧,在您的情况下,
Reg看起来像正则表达式的一部分。那么它应该是${lines} = Get Lines Matching Regexp ${result} ^(https?://)?(www\\.)?(instagr(\\.am|am\\.com))/([a-zA-Z0-9_.-]+)/$。让我们回到括号表达式和捕获组。为了使它不区分大小写和多行,你需要(?im),(?im)^(https?://)?(www\\.)?(instagr(\\.am|am\\.com))/([a-zA-Z0-9_.-]+)/$
标签: regex robotframework