Javascript RegExp如何在`for循环中检测和插入字符串`
我正在开发一个Javascript RegExp如何在`for循环中检测和插入字符串`,javascript,html,regex,for-loop,Javascript,Html,Regex,For Loop,我正在开发一个小插件,它检测for loop是否长时间运行,如果不是,则运行循环,当限制超过时,则停止循环 因此,我在名为timeout() 比如: UserCode = 'for(i=0;timeout() && i<=50000;i++){for(j=0;timeout() && j<5000;j++){$("#ps").append("hey I am a bug<br>");}}' eval(UserCode); 给我一个想
小插件
,它检测for loop
是否长时间运行,如果不是,则运行循环,当限制超过时,则停止循环
因此,我在名为timeout()
比如:
UserCode = 'for(i=0;timeout() && i<=50000;i++){for(j=0;timeout() && j<5000;j++){$("#ps").append("hey I am a bug<br>");}}'
eval(UserCode);
给我一个想法,我将如何实现这一点,并把我的功能放在正确的位置
使用此正则表达式:
/for\(\w+=\d;/g
并将其替换为:
$&timeout()
一辆JSFIDLE正在路上
只需像这样使用上述内容:
var UserCode = 'for(i=0; && i<=50000;i++){for(j=0; && j<5000;j++){$("#ps").append("hey I am a bug<br>");}}'
UserCode = UserCode.replace(/for\(\w+=\d;/g, '$&timeout()');
eval(UserCode);
var UserCode='for(i=0;&&i这与regex有什么关系?应该适当地使用标记,因为我拥有的代码是user code
,它是一个字符串,我想在其中应用regex..@Amitplease这样做!等待回答:)是的,现在我有理由问一个私人问题了吗?@AmitOf当然是@AshishMishra这是我的fb档案照片所以,你看起来是个很小的男孩?是吗?@AmitAmazing yarr…坚持下去!!我很高兴见到你!!:)@Amit@AshishMishra到这个聊天室来
var UserCode = 'for(i=0; && i<=50000;i++){for(j=0; && j<5000;j++){$("#ps").append("hey I am a bug<br>");}}'
UserCode = UserCode.replace(/for\(\w+=\d;/g, '$&timeout()');
eval(UserCode);