If I'm understanding you correctly, it would be a job for regular

var match = /element\[[0-9]+\]\[([^\]]+)\]/.exec(element.name);
if (match) {
  // Use match[1], which contains "Theme"

Live example: http://jsbin.com/ozoyi3/2

That allows extra stuff at both the beginning and the end of the name;
if you want to tighten it up, add ^ at the beginning and $ at the end:

The regex says: Look for 'element[' followed by one or more digits
followed by '][' followed by (and capturing) anything that isn't a
']', followed by a ']'. Captures are stored starting at index 1 in the
match result array, so if `match` doesn't come back `null`, we look in
`match[1]` for the value that was in the second set of `[]`s.

T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com

On Apr 8, 5:14 pm, Walter Lee Davis <wa...@wdstudio.com> wrote:
> If I have a string value like this  as the name attribute of a form  
> element:
> element[312]​[Theme]
> How would I grab the value of that field while ignoring the numerical  
> index, and using the second index value (Theme) to clue in my  
> application about where to place the value? Would this be a job for  
> regular expressions, or is there some aspect of array notation that I  
> can exploit to do the same thing?
> Walter

You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to