问题
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