A regular expression would likely look like this:
/http:\/\/example\.com\/api\/v3\?\S+/g
Make sure to escape each /
and ?
with a backslash. \S+
yields all subsequent non-space characters. You can also try [^\s"]+
instead of \S
if you also want to exclude quote marks.
In my experience, though, regexes are usually slower than working on already parsed objects directly, so I’d recommend you try these Array
and DOM functions instead:
Get all elements, map them to their attributes and filter those that start with http://example.com/api/v3?
, reduce all attributes lists to one Array and map those attributes to their values.
Array.from(document.querySelectorAll("*"))
.map(elem => Object.values(elem.attributes)
.filter(attr => attr.value.startsWith("http://example.com/api/v3?")))
.reduce((list, attrList) => list.concat(attrList), [])
.map(attr => attr.value);
You can find polyfills for ES6 and ES5 functions and can use Babel or related tools to convert the code to ES5 (or replace the arrow functions by hand).
2
solved Regex to return all attributes of a web page that starts by a specific value