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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:27:37+00:00 2026-06-11T13:27:37+00:00

I have input strings that look something like these inspect [foo – bar] with

  • 0

I have input strings that look something like these

inspect [foo - bar] with [errors - 15] 
create [doodle]
force delete [quux]

That is, lines which contain information within square brackets.

What I want is to take one of those lines at a time and get an array like

["inspect", "[foo - bar], "with", "[errors - 15]"]

Using a regular expression it’s easy to collect the bracketed expressions and the parts between the bracketed expressions separately:

var src = "inspect [foo - bar] with [errors - 15]"
var regexBracketed = /\[[a-zA-Z0-9_\- ]+\]/g;

// this returns an array of the bracketed expressions
console.log(src.match(regexBracketed));

// and this returns an array of the parts between the expressions
console.log(src.split(regexBracketed));

Is there a simple way to get everything in just one array? Maybe I’m attacking this entirely the wrong way.

  • 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-06-11T13:27:38+00:00Added an answer on June 11, 2026 at 1:27 pm

    are you referring to groups (capturing parentheses)? /(.*)/ ?

    https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Regular_Expressions#Using_Parenthesized_Substring_Matches

    for example, if you want to capture the strings in the brackets, then you can use this:

    var r=/^\s*[^\[\]]*\[([^\[\]]+)\](?:[^\[\]]*\[([^\[\]]*)\])?\s*$/;
    var m = "inspect [foo - bar] with [errors - 15] ".match(r);
    console.log(m[1], m[2]);
    

    you can add \s* to the expression to trim whitespace too.

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

Sidebar

Related Questions

I have an input string that will look something like Monday 2:00 pm and
I have 2 arrays in PHP that look something like this: $rows = array(11,12,14,14,11,13,12,11);
I have a string that will look something like this: I'm sorry the code
Suppose I have an HTML page that looks something like this: <html><body> 00123 <input
I have an array of input strings that contains either email addresses or account
I have a string input that i do not know whether or not is
I have a function that takes an input string and then runs the string
I have a method that hash input string to generate MD5 pass from it
I have a string input = "maybe (this is | that was) some ((nice
I need to create an input form that will allow a user to enter

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.