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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:26:15+00:00 2026-06-13T12:26:15+00:00

I am receiving a JSON post into my Rails 3 application. I am then

  • 0

I am receiving a JSON post into my Rails 3 application. I am then parsing each of the values and inserting them into the application database. It’s all working well but now I would like to modify the received values before inserting them into the database.

:subject => email_payload['subject']

As the above code shows, I am inserting the received value for ‘subject’ into the column named ‘subject’.

In the example above the received value is like this:

Results from Example Company - Surname/Firstname/[12345]

What I would like to do is strip everything out except the numerical value between the []. So the value that’s inserted into the database is simply:

12345

I can, presumably, just select anything from 0-9 but how do I add regex to the received string?

None of the following seem to work:

['subject.gsub!([0-9])']
['subject'.gsub!([0-9])]
['subject'].gsub!([0-9])

I’ve tested the Regex here http://rubular.com/r/AVFkm3A440

  • 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-13T12:26:16+00:00Added an answer on June 13, 2026 at 12:26 pm

    Since you are applying the .gsub() to the value returned by the hash key email_payload['subject'], the method belongs chained outside the closing ].

    Your regular expression is missing its / delimiters. To capture the group as a whole, add a + as in /[^0-9]+/. The ^ will match all non-digit characters, and then .gsub() will replace them with an empty string. So the pattern below will mutate the key email_payload['subject'] in place

    email_payload['subject'] = 'Results from Example Company - Surname/Firstname/[12345]'
    
    email_payload['subject'].gsub!(/[^0-9]+/, '')
    >> "12345"
    # gsub!() has mutated the value:
    puts email_payload['subject']
    >> 12345
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are currently receiving a heavy duty result into our iPhone application via https
I'm trying to post JSON between URLs in my app. The receiving URL expects
Am receiving null from json post using jquery. see my code below in order.
I'm receiving a JSON string in a PHP page : $JSON = $_POST['submit']; $Array
After my last question was solved the JSON I'm receiving from the server changed
I am receiving an image, title and description from a json file and i
I am receiving Invalid Index COM exception when calling Excel.AddIns.Item[0] . Excel.AddIns.Count works all
I have a MVC 4 web api application that receives json objects and uses
I'm sending a json string to a REST server and receiving one in return,
I have a controller action that is receiving a complex object via JSON. The

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.