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
答案 0 :(得分:0)
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>