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

  • SEARCH
  • Home
  • 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 9277675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:10:02+00:00 2026-06-18T17:10:02+00:00

I’m grabbing values from a grails select tag, and need to strip out the

  • 0

I’m grabbing values from a grails select tag, and need to strip out the extra characters that jQuery is grabbing and format the string before passing it off to our BIRT report server.

The list from grails looks something like:

Term:
    [201360, Continuing Ed Automn 2013]
    [201350, Summer Session 2013]
    ...
College
    [AS, College of Arts and Sciences]
    [BA, College of Business Administration]
    ...

This is an example of what is being serialized by jQuery when a selection is made on both of the select lists:

Term=%5B201360%2C+Continuing+Ed+Autumn+2013%5D&College=%5BBA%2C+School+of+Business+Admin%5D 

I would like to have the final value be something like

Term=201360&College=BA

The problem with doing a straight substring is the number of variables can change, and either are optional. There could be 1, or there could be 20.

How would I go about extracting only the needed pieces?

  • 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-18T17:10:04+00:00Added an answer on June 18, 2026 at 5:10 pm

    I am not sure why you end up with that kind of data. Anyway:

    // I guess + mean space here, so I convert it back to space before
    // doing percentage unescape
    var convertedInput = unescape(inputString.replace(/\+/g, ' '));
    var output = convertedInput.replace(/\[ *([^,]+?) *,[^\]]+\]/g, '$1')
    

    The regex may look slightly more complex than necessary, but I remove extra leading and trailing spaces, if any, in the first item inside [].

    Explanation:

    \[ *([^,]+?) *,[^\]]+\]
    
    • The whole regex tries to match the value part in key-value pair of the form key=[item1, item2, ...]. It will capture the first item and throw away the rest.
    • \[ and \] are literal [ and ] characters.
    •  *([^,]+?) *,: Eat up leading space  *. Then consume and capture the token ([^,]+?), assumed to have no comma [^,], and due to the lazy quantifier +? will consume as little as possible before encountering the sequence: optional space followed by (the first) comma  *,.
    • [^\]]+: Consume (and later throw away) everything that is not ]. It will stop at ] (or end of string, but not the case here).

    Assumptions:

    • [] are balanced, and there are no nesting.
    • No comma , inside the items to be extracted.
    • The key-value pairs to be modified are of the form key=[item1, item2, ...]
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I know there's a lot of other questions out there that deal with this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need to clean up various Word 'smart' characters in user input, including but
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

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.