I need to find path information from a string using jquery and push the results into an array.
The string output looks like;
"var rsr = Raphael('rsr', '270', '266');
var path_a = rsr.path('M144.869,199c0,7.659-5.479,13.139-13.14,
13.139 c-7.659,0-14.598-5.479-14.598-13.139s6.209-13.139,13.869-
13.139S144.869,191.341,144.869,199z'); path_a.attr({fill: 'non .... etc"
I need to retrieve every occurrence of the path information with in rsr.path() ;
How would i go about achieving this? using $.each on my string with a regex?
thanks cam
JavaScript will let you do this with a regular expression:
var s = " var rsr = Raphael('rsr', '270', '266'); var path_a = rsr.path('M144.869,199c0,7.659-5.479,13.139-13.14, 13.139 c-7.659,0-14.598-5.479-14.598-13.139s6.209-13.139,13.869- 13.139S144.869,191.341,144.869,199z'); path_a.attr({fill: 'non .... etc";
var regex = /M144\.869(.+?)869,199z/g;
var matches = regex.exec(s);
matches[0] then contains the capture group.
i found this worked..
$(document).ready(function(){
$('form.svg-convert').submit(function(event){
var content = $(this).find('textarea').val();
process(content);
event.preventDefault();
})
})
var process = function(c){
var content = c,
paths = [];
var contentSplit = content.split('path(');
contentSplit.shift();
$.each(contentSplit,function(i,v){
var path = v.split(')');
path = path[0];
paths.push(path);
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.