With Native Javascript this would be the code:
document.querySelectorAll('[id^=starting][id$=ending]');
or
document.querySelectorAll('[id^='+startingString+'][id$='+endingString+']');
This will get an element which starts with the specified string AND ends with the specified string.
Edit: And to do an "OR", put a space between them:
document.querySelectorAll('[id^=starting] [id$=ending]');