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 7625501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:12:01+00:00 2026-05-31T05:12:01+00:00

I am just getting started with regex in JavaScript (and in general) and I

  • 0

I am just getting started with regex in JavaScript (and in general) and I have come across an oddity that I can’t seem to find an explanation for using Google.

Without getting into to much detail, I am using the following expression:

/(^sw:\s?(-?\d{1,3}.\d{1,6})\sne:\s?(-?\d{1,3}.\d{1,6})$)/i

Which is matching user input like:

sw: -27.990344 ne: 150.234562

With the following console.log output:

["sw: -27.345455 ne: 180.234567", "sw: -27.345455 ne: 180.234567", "-27.345455", "180.234567"]

0 "sw: -27.345455 ne: 180.234567"   
1 "sw: -27.345455 ne: 180.234567"   
2 "-27.345455"  
3 "180.234567"

index 0
input "sw: -27.345455 ne: 180.234567"

My Question is: Why is index 0 and 1 returning the user supplied input and the actual data I would like is return as index 2 and 3?

I assume its relative to my expression, but don’t know enough about it to be sure its not just normal behaviour.

Any help appreciated.

  • 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-31T05:12:02+00:00Added an answer on May 31, 2026 at 5:12 am

    Index 0 is always the complete match, the capturing groups are starting at index 1.

    The capturing groups are numbered by their opening brackets, first opening bracket is group 1, second opening bracket is group 2, …

    You have brackets around your complete expression, so this is the first capturing group. ==> This outer brackets are not needed, you can remove them and then your groups will start at index 1.

    For more information about capturing groups you can have a look at /www.regular-expressions.info, this is a very good resource about regexes.

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

Sidebar

Related Questions

Just getting started with factory girl, and I've come across a problem with sequencing:
Just getting started with MSpec and I can't seem to quite get my first
Just getting started with Obj-C and iOS programming. I have some code that loads
I'm just getting started with a project that combines GWT, Google App Engine and
I'm just getting started with a project and wondered if someone can let me
I am just getting started with the Facebook JavaScript SDK, all I want to
Hi I'm just getting started on the v4 CTP so I can see me
Just getting started using MVC in ASP.NET, I'm going to have it so users
Just getting started on Scala Actors. The Scala website says: Thread-blocking operations can be
I'm just getting started with learning about Unit testing (and TDD in general). My

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.