Reputation: 4318
I am trying to pull the latest revision number using a regular expression that is not working. Could someone helped a novice regexer with this:
revision: 2020
stdout.match(/^r(\d+)/m)[1])
Thank you for any help you can give
EDIT
I should have put my whole task here so all would know what I am trying to do.
grunt.registerTask('version', 'Updating to latest revision',
function () {
var done = this.async();
grunt.util.spawn({
cmd: 'svn info',
args: ['-r HEAD']
}, function (err, result, code) {
var output = result.stdout;
if (output) {
var revision = result.stdout.match(/\d+/)[0];
grunt.file.write('web/version2.js', 'var UIVERSION = ' + revision);
}
done();
});
}
);
Upvotes: 0
Views: 216
Reputation: 63524
You should just be able to do \d+
, and then pull the first element, like:
var str = 'revision: 2020';
var regex = /\d+/
var number = str.match(regex)[0]; // '2020'
And if you want it as an integer rather than a string, just add a +
to the expression:
var number = +str.match(regex)[0]; // 2020
Upvotes: 1