Regex 使用正则表达式查找并获取特定单词
我试图从返回的数据中找到并获取特定的单词 当我执行一个局部命令时,Regex 使用正则表达式查找并获取特定单词,regex,node.js,shell,Regex,Node.js,Shell,我试图从返回的数据中找到并获取特定的单词 当我执行一个局部命令时,console.log(stdout)打印下面的数据 commit e6c4236951634c67218172d742 Author:ttpn <testuser@gmail.com> Date: Mon Jun 9 10:18:04 2014 -0700 Fix it dersk reset .......... ........... ); } 如何从中获取电子邮件idtestuser@gmai
console.log(stdout)
打印下面的数据
commit e6c4236951634c67218172d742
Author:ttpn <testuser@gmail.com>
Date: Mon Jun 9 10:18:04 2014 -0700
Fix it dersk reset
..........
...........
);
}
如何从中获取电子邮件id
testuser@gmail.com
可以使用正则表达式吗?此正则表达式将捕获您想要添加到组1和组2的数据(在上,查看右窗格中的捕获组):
commit(\S+[\r\n]*作者:[^
以下是如何在JS中使用此选项:
var regex = /commit (\S+)[\r\n]*Author:[^<]*<([^>]*)>/;
var match = regex.exec(string);
if (match != null) {
theid = match[1];
theemail = match[2];
}
var regex=/commit(\S+[\r\n]*作者:[^/;
var match=regex.exec(字符串);
如果(匹配!=null){
theid=匹配[1];
theemail=匹配[2];
}
解释正则表达式
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
> # '>'
commit#“commit”
(#分组并捕获到\1:
\S+#非空白(除\n、\r、\t、\f、,
#和“”)(1次或多次(与
#(尽可能多)
)#结束\1
[\r\n]*#以下任意字符:'\r'(回车),
#“\n”(换行符)(0次或多次(匹配)
#尽可能多的钱)
作者:#“作者:”
[^]*#除“>”(0或更多)以外的任何字符
#次数(与最大金额匹配)
#(可能的)
)#结束\2
> # '>'
var regex = /commit (\S+)[\r\n]*Author:[^<]*<([^>]*)>/;
var match = regex.exec(string);
if (match != null) {
theid = match[1];
theemail = match[2];
}
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
> # '>'