I’m currently parsing some Gherkin files along with their associated step definition files. I’m wondering what the best way would be to extract the RegEx inside the step along with the code would be. For example, I have the following functions:
this.Given(/^I create an SNS topic with name "([^"]*)"$/, function(name, callback) {
var world = this;
this.request(null, 'createTopic', {Name: name}, callback, function (resp) {
world.topicArn = resp.data.TopicArn;
});
});
this.Given(/^I list the SNS topics$/, function(callback) {
this.request(null, 'listTopics', {}, callback);
});
I want to extract both the regex ^I create an SNS topic with name "([^"]*)"$
and function code:
var world = this;
this.request(null, 'createTopic', {Name: name}, callback, function (resp) {
world.topicArn = resp.data.TopicArn;
});
I’ve been able to extract the regex using the following regex: ‘this.(?:Given|Then|When)(/(.+?)/’
However, extracting the function code is a lot more tricky. How can I specify to extract everything from the first { to the last } for the function?
Uncle Ben is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.