Cucumber regex step definition

一笑奈何 提交于 2020-01-25 02:46:23

问题


Can someone explain what is the difference between

@When("some text (.*)")

and

@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.


回答1:


Here is explanation of couple of common regex :

.* matches anything (or nothing), literally “any character (except a newline) 0 or more times”

.+ matches at least one of anything

[0-9] or d matches a series of digits (or nothing)

[0-9]+ or d+ matches one or more digits

"[^"]*" matches something (or nothing) in double quotes

an? matches a or an (the question mark makes the n optional)

So, depending on your question, the difference is :

.* will take everything except the new lines, ([^\"]*) this will take everything also the new lines



来源:https://stackoverflow.com/questions/58819414/cucumber-regex-step-definition

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!