2

I want to match input fields that match the following pattern:

a_profile_contact_attributes_addresses_attributes_0_address b_store_contact_attributes_addresses_attributes_3_address somethingelse_contact_attributes_addresses_attributes_44_address

In other words, I want to use the following regex:

/contact_attributes_addresses_attributes_\d+_address/

Using jQuery, I tried the following but it returns an empty result set:

$('input[id*="contact_attributes_addresses_attributes_' + /\d+/ + '_address"]')

What might I be doing wrong?

Donato
  • 2,727
  • 6
  • 29
  • 59

2 Answers2

5

Use jquery filter to filter out based on your needs, like below:

$('input').filter(function() {
    return this.id.match(/contact_attributes_addresses_attributes_\d+_address/i)
}).css('prop', 'val'); // for example, set some css props for the matched elements
lshettyl
  • 8,166
  • 4
  • 25
  • 31
0

James Padolsey created a wonderful filter that allows regex to be used for selection.

Take a look at this question:

jQuery selector regular expressions

Community
  • 1
  • 1
Ragnar
  • 4,393
  • 1
  • 27
  • 40