我正在阅读PDF文件。在PDF文件的一页中,我想从该字符串行中获取日期“插图截至:2016年12月9日”。我能够使用正则表达式来搜索“插图为:”。但我怎么不能得到日期。我需要返回正则表达式的结果。我不需要返回我搜索的相同字符串。如何在字符串匹配时在行尾获得下一个字符串
i tried this but it only return me Illustration as of :
const regex = /Illustration as of:/g;
const str = `Illustration as of: December 9, 2016`;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
我只需要回到这个结果2016年12月9日
'(:插图为:??\ S)(一月|二月|三月|五月|六月|七月|八月|九月|十月|十一月|十二月)\ d {1, 2},\ s?\ d {4}'或'(?:图示为:\ s?)。+ $' –
它看起来很复杂。 –
第二个很简单,只要找'Illustraton作为:'并且把它放在后面直到行结束。 –