Reputation: 25348
I have a string formatted like this:
item_questions_attributes_abc123_id
I'm specifically trying to get the abc123
bit. That string can be any alphanumeric of any case. No special characters or spaces.
I'm using jQuery, though I'm certainly fine with using straight javascript if that's the best solution.
Upvotes: 2
Views: 6450
Reputation: 3211
use split method of javascript and then use 2nd last index you will have your required data.
Upvotes: 0
Reputation: 35793
If it's always the 4th part of the string you can use split.
var original = 'item_questions_attributes_abc123_id';
var result = original.split('_')[3];
Upvotes: 7