简体   繁体   English

Javascript-从括号内获取字符串的内容

[英]Javascript - Get the content of a string from inside a parenthesis

I have a string which I get back from an ajax request. 我有一个从ajax请求中获取的字符串。 The string is in this format: 字符串格式如下:

  POINT(417135.05230943 4187636.37572952)

What I want is to get the content in the parenthesis to use it to make a marker (latitude, longitude). 我想要的是获取括号中的内容,以使用它来做一个标记(纬度,经度)。

Right now I do this: 现在,我这样做:

response = response.replace("POINT(",'');
response = response.replace(")",'');
response = response.replace(" ",',');
//alert(response);
var latlotArr = response.split(',');

Which I don't like at all. 我一点都不喜欢。 Is there another way to do it? 还有另一种方法吗? I suppose is not possible to convert this to JSon. 我想不可能将其转换为JSon。 What alternatives do I have? 我有什么选择?

Bunch of ways to do it. 一堆的方法来做到这一点。

One way is a basic regular expression to match the two groups of numbers separated by a space. 一种方法是使用基本正则表达式来匹配由空格分隔的两组数字。

var str = "POINT(417135.05230943 4187636.37572952)";
var points = str.match(/(\d+.\d+)\s(\d+.\d+)/);
console.log(points[1], points[2]);

You can get more specific if you want, up to you. 如果需要,您可以根据自己的需要获得更多具体信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM