str= "2007-01-01 12:12:12 问题 1234 "
或str= "sdfd 2007-01-01 12:12:12 问题 "
或str= "2007-01-01 12:12sdfdf "
或str= "a 2007-01-01 sdddd "
我想取出这些字符串中的时间,如何办?
------解决方案--------------------
先用split分割,再看每个里是否包含2个-
------解决方案--------------------
<textarea id=textarea1>
str= "2007-01-01 12:12:12 问题 1234 "
或str= "sdfd 2007-01-01 12:12:12 问题 "
或str= "2007-01-01 12:12sdfdf "
或str= "a 2007-01-01 sdddd "
</textarea>
<script>
alert(aaa(textarea1.value))
function aaa(x)
{
var rtn= " ";
var arr = x.match(/(\d+[-\:\s])+\d+/ig);
for(i=0;i <arr.length;i++)
{
rtn += arr[i] + "\n ";
}
return(rtn);
}
</script>