Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.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 在Jquery中使用Match只返回一个值_Javascript_Jquery_Regex_Match - Fatal编程技术网

Javascript 在Jquery中使用Match只返回一个值

Javascript 在Jquery中使用Match只返回一个值,javascript,jquery,regex,match,Javascript,Jquery,Regex,Match,我试图使用“Match”来过滤文本区域中的一些值,但我的代码只适用于第一行,只返回“one.png;1” 我需要获取“text2”div中的所有值,比如:“one.png;1/two.png;2/three.png;3” $(文档).ready(函数(){ var dataimg=$('#text').text().match('url_image=“(.*)”); var datasub=$('#text').text().match('sub=(.*)); $(“#text2”).appe

我试图使用“Match”来过滤文本区域中的一些值,但我的代码只适用于第一行,只返回“one.png;1”

我需要获取“text2”div中的所有值,比如:“one.png;1/two.png;2/three.png;3”

$(文档).ready(函数(){
var dataimg=$('#text').text().match('url_image=“(.*)”);
var datasub=$('#text').text().match('sub=(.*));
$(“#text2”).append(dataimg[1]).append(“;”).append(datasub[1]);
});

url_image=“one.png”;sub=1;url_image=“two.png”;sub=2;url_image=“three.png”;sub=3;

如果您只是尝试更新文本格式,则可以使用全局替换,例如:

/url_image="([^"]+)"; sub=(.*);/g
并将匹配项替换为“
”$1$2'

$('#text2').text(函数(){
返回$('#text').text().replace(/url#u image=“([^“]+)”;sub=(.*);/g,'$1;$2');
});

url_image=“one.png”;sub=1;
url_image=“two.png”;sub=2;
url_image=“three.png”;sub=3;