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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:57:38+00:00 2026-05-18T11:57:38+00:00

I have the following variable which is the selected text of a select box.

  • 0

I have the following variable which is the selected text of a select box. This is the select box markup.

<select name="SELECT___100E___7">
<option selected="" value="25">Beige/Almond</option>
<option value="21">Blue [Subtract -$1.00]</option>
<option value="27">Chrome [Subtract -$2.00]</option>
<option value="29">Red [Add $1.00]</option>
</select>

Variable test_var hold the selected text…

$('select[name^="SELECT___"]').change(function(){
var test_var = $(this).find("option:selected").text();
});

So what I would like to do is remove all characters except for the amount, also removing the “$”. So if “Red [Add $1.00]” is selected I want to have test_var equal to 1.00

Having trouble figuring out the regexp to do this.

  • 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-18T11:57:39+00:00Added an answer on May 18, 2026 at 11:57 am

    This should do it (er, actually, see the update below):

    var m = test_var.match(/(-?)\$([0-9\.]+)/);
    var result = m.length > 0 ? m[1] : "";
    

    Live example

    What that says is “look for a $ followed by a series of digits and . characters, and grab as many of that series as you can when matching.” The resulting match array will have the complete matching string (including the $ in position 0, and then the first (and only) capture group at position 1 — and so we grab that.


    Update Er, um, if you need to capture the - sign (and I’m guessing you do), change that to this:

      var m = test_var.match(/(-?)\$([0-9\.]+)/);
      var result = m.length > 0 ? m[1] + m[2] : "";
    

    Live example

    That uses an optional capture for the - if it’s present before the $, and then combines the two capture groups (m[1] and m[2]; m[1] will be “” if there’s no -).

    Results (for example):

    Red [Add $1.00]        => 1.00
    Blue [Subtract -$1.00] => -1.00

    Off-topic: Beware localization! Because in some locales, those .s will be ,s, e.g., “€1,00” for one Euro in Germany.

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

Sidebar

Related Questions

What I have is following: <xsl:variable name=myvar select=.//spss:category[((not @varName) or @varName=$colVarName) and @text=$series]/spss:cell/@text/> What
I have the following XSLT variable: <xsl:variable name=superid select=/contentdata/id/> Furthermore, I have a node
I have text documents like the following which contain single and multiple variables: title::
I have the following variable that accepts a file name: var xtr = new
I have the following variable which returns my URL as needed. But i need
I have the following variable: NSNumber *consumption = [dict objectForKey:@con]; Which returns 42. How
I have a variable which contains the following string: AL,CA,TN,VA,NY I have no control
I have a variable which contains the following string placeholder = <strong>Total Damage:</strong> $70,000.00
I have the following variable which contains the following string. I would like to
I have the following table variable in SQL Server 2005: DECLARE @results TABLE (id

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.