Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6566141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:10:53+00:00 2026-05-25T14:10:53+00:00

I’m doing a small javascript method, which receive a list of point, and I’ve

  • 0

I’m doing a small javascript method, which receive a list of point, and I’ve to read those points to create a Polygon in a google map.

I receive those point on the form:

(lat, long), (lat, long),(lat, long)

So I’ve done the following regex:

\(\s*([0-9.-]+)\s*,\s([0-9.-]+)\s*\)

I’ve tested it with RegexPal and the exact data I receive:

(25.774252, -80.190262),(18.466465, -66.118292),(32.321384, -64.75737),(25.774252, -80.190262)

and it works, so why when I’ve this code in my javascript, I receive null in the result?

var polygons="(25.774252, -80.190262),(18.466465, -66.118292),(32.321384, -64.75737),(25.774252, -80.190262)";
var reg = new RegExp("/\(\s*([0-9.-]+)\s*,\s([0-9.-]+)\s*\)/g");
var result = polygons.match(reg);

I’ve no javascript error when executing(with debug mode of google chrome). This code is hosted in a javascript function which is in a included JS file. This method is called in the OnLoad method.

I’ve searched a lot, but I can’t find why this isn’t working. Thank you very much!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:10:54+00:00Added an answer on May 25, 2026 at 2:10 pm

    Use a regex literal [MDN]:

    var reg = /\(\s*([0-9.-]+)\s*,\s([0-9.-]+)\s*\)/g;
    

    You are making two errors when you use RegExp [MDN]:

    • The “delimiters” / are should not be part of the expression
    • If you define an expression as string, you have to escape the backslash, because it is the escape character in strings

    Furthermore, modifiers are passed as second argument to the function.

    So if you wanted to use RegExp (which you don’t have to in this case), the equivalent would be:

    var reg = new RegExp("\\(\\s*([0-9.-]+)\\s*,\\s([0-9.-]+)\\s*\\)", "g");
    

    (and I think now you see why regex literals are more convenient)


    I always find it helpful to copy and past a RegExp expression in the console and see its output. Taking your original expression, we get:

    /(s*([0-9.-]+)s*,s([0-9.-]+)s*)/g
    

    which means that the expressions tries to match /, s and g literally and the parens () are still treated as special characters.


    Update: .match() returns an array:

    ["(25.774252, -80.190262)", "(18.466465, -66.118292)", ... ]
    

    which does not seem to be very useful.

    You have to use .exec() [MDN] to extract the numbers:

    ["(25.774252, -80.190262)", "25.774252", "-80.190262"]
    

    This has to be called repeatedly until the whole strings was processed.

    Example:

    var reg = /\(\s*([0-9.-]+)\s*,\s([0-9.-]+)\s*\)/g;
    var result, points = [];
    
    while((result = reg.exec(polygons)) !== null) {
        points.push([+result[1], +result[2]]);
    }
    

    This creates an array of arrays and the unary plus (+) will convert the strings into numbers:

    [
        [25.774252, -80.190262], 
        [18.466465, -66.118292], 
        ...
    ]
    

    Of course if you want the values as strings and not as numbers, you can just omit the +.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.