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?

2 Answers 2

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 
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.