我试图通过字符串来查找 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
}
感谢您的帮助。
最佳答案
return myLongString.match(/\b1[98]\d\d\b/g);
关于JavaScript 使用正则表达式在长字符串中查找单词 "19XX"或 "18XX",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6740799/