Created
December 1, 2011 19:48
-
-
Save jgarber623/1419329 to your computer and use it in GitHub Desktop.
An obtuse Regular Expression that'll replace indices in input @name and @id attributes in multi-model Rails forms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// RegExplanation: Match last occurrence of "_<string>_" and replace with "_<new_string>_" | |
some_string.replace( /^(.*)_.+_(.*?)$/, "$1_" + new_fields_index + "_$2" ), | |
// RegExplanation: Match last occurrence of "][<string>][" and replace with "][<new_string>][" | |
some_string.replace( /^(.*)\]\[.+\]\[(.*?)$/, "$1\]\[" + new_fields_index + "\]\[$2" ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment