c# - Regex replace for swapping order of numbers in a string -


i put linq query swaps numbers in list. wondering if theres mroe elegant way using regex.

var str = " <gml:coordinates>36.230968,21.971054 36.633873,19.144154 38.007656,19.423254 37.606049,22.303988 36.230968,21.971054</gml:coordinates>"; var test = string.format("<gml:coordinates>{0}</gml:coordinates>", string.join(" ", regex.match(str, "<gml:coordinates>(.*)</gml:coordinates>").groups[1].value.split(' ').select(d => string.join(",", d.split(',').reverse())))); //<gml:coordinates>21.971054,36.230968 19.144154,36.633873 19.423254,38.007656 22.303988,37.606049 21.971054,36.230968</gml:coordinates> 

the following should work:

regex.replace(str, @"([\d.]*),([\d.]*)", "$2,$1") 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -