I have the following input elements:
<input id="AAA_RandomString_BBB" type="text" />
<input id="AAA_RandomString_BBB_Start" type="text" />
<input id="AAA_RandomString_BBB_End" type="text" />
AAA & BBB are constants and I will always know what they are. However RandomString will always be random.
I want to get the value of AAA_RandomString_BBB. I do not want the values from the input elements with ID ending in either _Start or _End.
I tried the folowing:
$('[id^="AAA_"]')
But the above selects all of the input elements that have an ID starting with “AAA_”
I need some way to select using a regex type syntax like:
$('[id^="AAA_(.+?)_BBB"]')
Is this possible? If not, can anyone suggest a method of selecting
You can combine both selectors in a multiple attribute selector.
It will return all the elements that matches all the specified attribute filters:
[id^=AAA_]matches elements withidattribute starting withAAA_, and[id$=_BBB]matches elements withidattribute ending with_BBB.Another generic alternatives:
:regex()selector,.filter()-based approach.