Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.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 字符串拆分<;href>;_Javascript_Jquery_Html - Fatal编程技术网

Javascript 字符串拆分<;href>;

Javascript 字符串拆分<;href>;,javascript,jquery,html,Javascript,Jquery,Html,我是Jquery的新手。我需要提取时间并将其附加到标记的末尾 <html> 5:00 am - 8:am <a href='/sites/ERR/ERR/HC/ERRC Items/DispForm.aspx?ID=4' target="_blank">Implementation of two gateway</a>' </html> 上午5:00-8:00' 格式化后,我的字符串应如下所示: '<a href='/sites/ERR

我是
Jquery的新手。
我需要提取时间并将其附加到标记的末尾

<html>
5:00 am - 8:am <a href='/sites/ERR/ERR/HC/ERRC Items/DispForm.aspx?ID=4' target="_blank">Implementation of two gateway</a>'
</html>

上午5:00-8:00'
格式化后,我的字符串应如下所示:

'<a href='/sites/ERR/ERR/HC/ERRC Items/DispForm.aspx?ID=4' target='_blank">Implementation of two gateway</a> 5:00 am- 8: am '
“上午5:00-上午8:00”

请您帮忙好吗?

您可以用一个简单的正则表达式找到时间并调整字符串:

//初始化时间字符串
var timeString=“上午5:00-上午5:00实现两个网关”;
//初始化正则表达式
var regex=/\d:\d?\d?\s?(am | pm)?\s?-?\s?\d:\d?\d?\s?(am | pm)?/g;
//打印之前
log(“BEFORE:+timeString”);
//运行正则表达式
match=regex.exec(timeString);
//检查是否找到时间
如果(匹配!=null){
//删除时间值
timeString=timeString.replace(匹配[0],“”);
//添加结束时间
时间字符串=时间字符串+“”+匹配[0];
}
//打印后

log(“在:+timeString之后”)@Indu527没问题!如果这个答案对你有帮助,请接受它来结束问题嗨,我的一些字符串包含上午5:00-8:00。如何从stringHey tony中提取开始和结束时间,我得到以下输出:两个防火墙的5:00 am实现。我希望输出如下:两个防火墙的实现:上午5:00到8:00