黄瓜正则表达式步骤定义 [英] Cucumber regex step definition
问题描述
有人可以解释两者之间的区别吗
Can someone explain what is the difference between
@When("some text (.*)")
和
@When("^some text ([^\"]*)$")
?
前者在使用简单步骤时有效,但是在使用数据表时,它仅映射到第一个表项.
The former worked when using a straightforward step, but when using a data table it maps only to the first table item.
推荐答案
以下是几个常见正则表达式的说明:
Here is explanation of couple of common regex :
.* 匹配任何内容(或不匹配任何内容),字面意思是任何字符(换行符除外)0次或多次"
.* matches anything (or nothing), literally "any character (except a newline) 0 or more times"
.+ 至少匹配任何一项
[0-9] 或d 匹配一系列数字(或不匹配)
[0-9] or d matches a series of digits (or nothing)
[0-9] + 或 d + 匹配一个或多个数字
[0-9]+ or d+ matches one or more digits
"[^"] *"匹配双引号中的某项(或不匹配)
"[^"]*" matches something (or nothing) in double quotes
an?匹配a或an(问号使n可选)
an? matches a or an (the question mark makes the n optional)
因此,根据您的问题,不同之处是:
.*将采用除新行以外的所有内容, ([^ \] *),这将使所有内容也换上新行
.* will take everything except the new lines, ([^\"]*) this will take everything also the new lines
这篇关于黄瓜正则表达式步骤定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!