繁体   English   中英

正则表达式从JavaScript中的匹配字符串中获取下一行值?

[英]Regex to get next line value from matched string in javascript?

function KeywordSearchRegards(string, regex1) 
{   
    while (Regards = regex1.exec(string)) 
    {
        //matchedValues.push(match[index]);
        matchedValuesRegards.push(Regards);
    }   
} 

var RegexRegard=/\s?Regards,\s?(.+)?/g;
var matchedValuesRegards=[];
var Regards ;

String1是:

问候,
XYZ

 var letter = document.querySelector('#letter').innerHTML, /* break down of the RegEx (?:regards|sincerely) the word regards or sincerely (non capture group), .* a comma if its there \\n+ one or many new lines (.*) capture the content to the next new line note: you could capture the rest of the document with ([\\s\\S]+) */ match = letter.match(/(?:regards|sincereley),*\\n+(.*)/im); matchRest = letter.match(/(?:regards|sincereley),*\\n+([\\s|\\S]+)/im) console.log( match[1] ); console.log( matchRest[1]); 
 <script src="http://codepen.io/synthet1c/pen/WrQapG.js"></script> <pre id="letter"> Hello Buddy, blah blah blah more cowebell. Regards, Christopher Walkin www.christopher-walkin.com 69 somewhere street </pre> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM