Reputation: 1457
Am trying to find and get particular word from a data returnd
While i executing a partiular command console.log(stdout)
prints below data
commit e6c4236951634c67218172d742
Author:ttpn <[email protected]>
Date: Mon Jun 9 10:18:04 2014 -0700
Fix it dersk reset
..........
...........
my code
var getemail = function (callback) {
var command = "git show ec6c4236951634c67218172d742";
exec(command, function (error, stdout, stderr) {
if (error !== null) {
console.log(error)
callback(error, null);
} else {
console.log(stdout) // prints the above data
}
})
; }
from this how can i get email id
[email protected]
using regular expression is it possible?
Upvotes: 2
Views: 50
Reputation: 41838
This regex will capture the data you want to Groups 1 and 2 (on the demo, look at the capture Groups in the right pane):
commit (\S+)[\r\n]*Author:[^<]*<([^>]*)>
Here is how to use this in JS:
var regex = /commit (\S+)[\r\n]*Author:[^<]*<([^>]*)>/;
var match = regex.exec(string);
if (match != null) {
theid = match[1];
theemail = match[2];
}
Explaining the Regex
commit # 'commit '
( # group and capture to \1:
\S+ # non-whitespace (all but \n, \r, \t, \f,
# and " ") (1 or more times (matching the
# most amount possible))
) # end of \1
[\r\n]* # any character of: '\r' (carriage return),
# '\n' (newline) (0 or more times (matching
# the most amount possible))
Author: # 'Author:'
[^<]* # any character except: '<' (0 or more times
# (matching the most amount possible))
< # '<'
( # group and capture to \2:
[^>]* # any character except: '>' (0 or more
# times (matching the most amount
# possible))
) # end of \2
> # '>'
Upvotes: 2