您的解決方案:
var string = '\nIn theoretical computer science and formal language theory, a regular expression (sometimes called a rational expression)[1][2] is a sequence of characters that define a search pattern, mainly for use in pattern matching with strings, or string matching, i.e. "find and replace"-like operations. The concept arose in the 1950s, when the American [email protected] mathematician Stephen Kleene formalized the description of a regular language, and came into common use with the Unix text processing utilities ed, an editor, and grep, a filter.\n\[email protected]\n\nSomeText\n\nname1/occupation1/state1\n\[email protected]\n\nRegexps are so useful in computing that the various systems to specify regexps have evolved to provide both a basic and extended standard for the grammar and syntax; modern regexps heavily augment the standard. Regexp processors are found in several search engines, search and replace dialogs of several word processors and text editors, and in the command lines of text processing utilities, such as sed and AWK.\n\nname2/occupation2/state2\n\[email protected]';
var someText = 'SomeText';
var regExp = new RegExp('\\[email protected]\\S+\\.\\S+','g');
var emails = string.split(someText)[1].match(regExp);
console.log(emails);
// ["[email protected]", "[email protected]"]
不要忘記使用RegExp
搜索電子郵件。我提供了最簡單的例子。
提示:捕獲組 – anubhava
但如何讓所有的結果SomeText後?請解釋 – PRECISION
使用indexOf和substring(或split)來獲取文本後的文本,然後匹配你所需要的。 –