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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:50:21+00:00 2026-06-09T17:50:21+00:00

I have the following string ( field_data ): <fieldset> <div class=’control-group’> <h5>New Side Dish</h5>

  • 0

I have the following string (field_data):

<fieldset>
    <div class='control-group'>
        <h5>New Side Dish</h5>
        <input id="menu_dishes_attributes_1344897592128_side_dishes_attributes_70308623619760_name" name="menu[dishes_attributes][1344897592128][side_dishes_attributes][70308623619760][name]" placeholder="Name" size="30" type="text" />
        <input id="menu_dishes_attributes_1344897592128_side_dishes_attributes_70308623619760__destroy" name="menu[dishes_attributes][1344897592128][side_dishes_attributes][70308623619760][_destroy]" type="hidden" value="false" />
        <input id="menu_dishes_attributes_1344897592128_side_dishes_attributes_70308623619760_price" name="menu[dishes_attributes][1344897592128][side_dishes_attributes][70308623619760][price]" placeholder="Price" size="30" type="text" />
        <input id="menu_dishes_attributes_1344897592128_side_dishes_attributes_70308623619760_restaurant_id" name="menu[dishes_attributes][1344897592128][side_dishes_attributes][70308623619760][restaurant_id]" type="hidden" />
        <a href="#" class="remove_fields">X</a>
    </div>
</fieldset>

And I want to grab the number between [side_dishes_attributes] and [restaurant_id] which is 70308623619760 and only the first occurrence or last occurrence but I basicly just need one instance of it.

I know you can use regular expression and filter but whenever I use any of these, it either returns all the digits in the string or it displays all the sets of the number in an incorrect output.

The number I’m grabbing is not static so it changes every iteration of the code but the names side_dishes_attributes and restaurant_id are constant.

Here’s what I’ve tried so far and here are the outputs:

field_data = $(this).data('fields')

start_pos = field_data.indexOf("side_dishes_attributes][")
end_pos = field_data.indexOf("][_destroy]", start_pos)
result_text = field_data.substring(start_pos, end_pos)
console.log("Result:", result_text)

Output:

Result: side_dishes_attributes][70208369492160][name]&quot; placeholder=&quot;Name&quot; size=&quot;30&quot; type=&quot;text&quot; /&gt;    &lt;input id=&quot;menu_dishes_attributes_70208370296900_side_dishes_attributes_70208369492160__destroy&quot; name=&quot;menu[dishes_attributes][70208370296900][side_dishes_attributes][70208369492160

And I’ve tried:

result = field_data.replace(/[^0-9]/g, "")
console.log(result)

Output:

227020836200328070208362003280702083620032803070208...

I have also tried playing around with this:

http://rubular.com/r/r5iowGGmw4

But I don’t know much about regular expressions to get this to work properly.

I’d appreciate any pointers. I’m doing all this in jQuery Coffeescript (but if you show me code in only jQuery, I can convert it over too).

Possible Answer?

start_pos = field_data.indexOf("side_dishes_attributes][") + 24
end_pos = field_data.indexOf("][name]", start_pos)
result_text = field_data.substring(start_pos, end_pos)
console.log("Result", result_text)

I got the right output using this but I was wondering if there is a better 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-09T17:50:23+00:00Added an answer on June 9, 2026 at 5:50 pm

    If your HTML string is stored in a variable, say str, you can do:

    var matches = str.match(/side_dishes_attributes_(\d+)_/);
    var number = matches[1];
    

    This will give you an array with two elements. The first is the full string that matches the regular expression “side_dishes_attributes_70308623619760”, and the second is the string captured by the parentheses, “70308623619760”. matches[1] will contain your number.

    By leaving out the g modifier, the expression only matches once, so it will return the number contained in the id of the first input

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

Sidebar

Related Questions

I have the following in a C# class: public static readonly SortedDictionary<string, string> Fields
I have the following string arrays: var myArray1 = new string[] {A, B, C};
I have the following class: public class Menu : TableServiceEntity { public string Order
i have the following view that contains an @Html.DropDownList :- <fieldset> <legend>Answer here</legend> <div
i have the following view:- <div id = partialWrapper> @using (Ajax.BeginForm(Create, Answer, new AjaxOptions
I Have a object which the following field : boost::unordered_map<std::string, std::shared_ptr<Foo> > m_liste_; I
I have a table in db2 which has the following fields int xyz; string
I have following string: Test, User < test@test.com >, Another, Test < another@test.com >,
I have following situation: String a = A Web crawler is a computer program
I have the following: string test = CustomerNumber; or string test2 = CustomerNumberHello; 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.