For your example below:
<link rel="multiply" type="service/math" src="path/to/service">
<link rel="substract" type="service/math" src="path/to/service">
You cannot use Regular Expression(Regex) but can use CSS Selector for querySelectorAll()
as well as querySelector()
as shown below. *You can see 6.2. Substring matching attribute selectors.
link[type^="service"]
can select all <link>
s whose type
attribute starts from service
:
document.querySelectorAll('link[type^="service"]');
// rel="multiply"'s <link> and rel="substract"'s <link>
[type^="service"]
can also select all <link>
s whose type
attribute starts from service
but I don't recommend it without link
because it is less specific so it may also select other elements:
document.querySelectorAll('[type^="service"]');
// rel="multiply"'s <link> and rel="substract"'s <link>
link[type*="service"]
can also select all <link>
s whose type
attribute contains service
:
document.querySelectorAll('link[type*="service"]');
// rel="multiply"'s <link> and rel="substract"'s <link>
In addition, link[src&="service"]
can also select all <link>
s whose src
attribute ends with service
:
document.querySelectorAll('link[src&="service"]');
// rel="multiply"'s <link> and rel="substract"'s <link>