我想编写步骤定义,这将适用于以下三个步骤之一。 我需要在双引号中选择最后两个参数。
Given I do "x"
Given I do "x", "y "
Given I do "x", "y ", " z"
我尝试了几种表达方式:
[Given(@"I do ""(.*)"", ""(.*)?"", ""(.*)?""")]
[Given(@"I do ""(.*)"", ""(.*)""?, ""(.*)""?")]
[Given(@"I do ""(.*)"", (""(.*)"")?, (""(.*)"")?")]
[Given(@"I do ""(.*)"", [""(.*)""]?, [""(.*)""]?")]
谢谢。
答案 0 :(得分:2)
答案 1 :(得分:1)
正则表达式:
I do \".*?\"(?:, \".*?\")*
说明:
/I do \".*?\"(?:, \".*?\")*/
I do matches the characters I do literally (case sensitive)
\" matches the character " literally (case sensitive)
.*? matches any character (except for line terminators)
*? Quantifier — Matches between zero and unlimited times, as few times as possible, expanding as needed (lazy)
\" matches the character " literally (case sensitive)
Non-capturing group (?:, \".*?\")*
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
, matches the characters , literally (case sensitive)
\" matches the character " literally (case sensitive)
.*? matches any character (except for line terminators)
\" matches the character " literally (case sensitive)