3

It is possibile to use this selector

$( "input[name~='man']" )

to identify any input in page which name contains the word 'man' but if i need to select, instead of a single word pattern i.e. 'man', a pattern containing two words like '(anything)checkbox(anything)man(anything)' so that

<input name="checkbox-foo-man">
<input name="checkbox-bar-man">
<input name="foo-checkbox-foo-man-foo">

gets selected? Possibily, impliying the right order that is 'checkbox' before 'man'

Sasha Grievus
  • 2,566
  • 5
  • 31
  • 58

1 Answers1

3

You can do it without regexes by combining selectors. I don't think there's a way to ensure the order this way though.

[name*="foo"][name*="bar"] {
  color: red;
}
<div name="foo-bar"> foo-bar </div> <!-- selected -->
<div name="bar-foo"> bar-foo </div> <!-- selected -->
<div name="foo-bar-baz"> foo-bar-baz </div> <!-- selected -->
<div name="foo-baz"> foo-baz </div>
<div name="bar-baz"> bar-baz </div>
c2huc2hu
  • 2,447
  • 17
  • 26
  • 1
    Maybe this helps you: `input[name*='man']:not([name^='man'])`. It selects all inputs that **contain** the word `man` but doesn't **start with** `man` – GreyRoofPigeon Nov 15 '17 at 15:23
  • Works like a charm! It was good to have the order, but I can deal with that. In my answer case, it was input[name*="checkbox"][name*="man"]. Thank you – Sasha Grievus Nov 15 '17 at 15:24