简体   繁体   English

正则表达式匹配所有黄瓜步骤并获取双引号

[英]Regex expression to match all cucumber steps and grab double quotes

As some background, I am attempting to write a generalized step that will match steps such as 作为一些背景知识,我试图编写一个广义的步骤来匹配诸如的步骤

When I "click" on "send" button
When I "press" on that "clear" thingy
When I "select" some kind of "money" maker

and give me what is in quotes. 并告诉我引号中的内容。

Optimally the step will look something like 最佳步骤看起来像

When(/regex here/) do |action, target|
   #do something here
end

I have tried (.*)"(.*)"(.*)"(.*)"(.*) and it does work but would require me to write the step such as 我试过(.*)"(.*)"(.*)"(.*)"(.*)它确实有效,但需要我写下这样的步骤

When(/(.*)"(.*)"(.*)"(.*)"(.*)/) do |unused, action, unused, target, unused|
   #do something here
end

another side effect is the entire step in the .feature file becomes highlighted, which is minor but would be nice to know exactly what is being grabbed, which is what is in double quotes. 另一个副作用是.feature文件中的整个步骤变得突出显示,这是次要的,但很高兴知道正在抓取什么,这是双引号。

What would be the Regex expression to accomplish this goal? 实现这一目标的正则表达式是什么?

Try using [^"] to match anything except " characters and only specify the groups you want to capture. 尝试使用[^"]匹配除"字符之外的任何内容,并仅指定要捕获的组。 For example: 例如:

When(/"([^"]*)"[^"]*"([^"]*)"/) do |action, target|
   #do something here
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM