Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript使用正则表达式查找单词;19XX“;或;18XX“;一丝不苟_Javascript_Html_Regex_String - Fatal编程技术网

JavaScript使用正则表达式查找单词;19XX“;或;18XX“;一丝不苟

JavaScript使用正则表达式查找单词;19XX“;或;18XX“;一丝不苟,javascript,html,regex,string,Javascript,Html,Regex,String,我试图通过一个字符串查找19XX或18XX格式的日期,其中XX可以是任何整数。以下是基本设置: var myLongString = "The Cold War (Russian: Холо́дная война́, Kholodnaya voĭna) was the continuing state from roughly 1946 to 1991 of political conflict..."; function getDates(myLongString) { //use

我试图通过一个字符串查找19XX或18XX格式的日期,其中XX可以是任何整数。以下是基本设置:

var myLongString = "The Cold War (Russian: Холо́дная война́, Kholodnaya voĭna) was the continuing state from roughly 1946 to 1991 of political conflict...";

function getDates(myLongString) {
    //use regular expressions to create a list of words in the "19XX" or "18XX" format
    //and then return that list
}


谢谢你的帮助

我会加上分词,否则你也会匹配数字的部分,比如19222和91822
return myLongString.match(/\b1[98]\d\d\b/g);