Reputation: 155
Currently I have the following structure (the ID at the end changes based on the code given by the shortner)
example.com/7NGOWX
example.com/7iTAXM
With javascript I am current using this code to change the url but it leaves the id.
<script>
document.body.innerHTML = document.body.innerHTML.replace(/example.com/g, '');
</script>
How can I make it so that it removes the entire url instead of leaving things like 7NGOWX
7iTAXM
behind?
Upvotes: 4
Views: 41
Reputation: 5486
Another option can be to use the URL() constructor and have it do the work.
for example
var url = new URL("http://example.com/7iTAXM");
console.log(url.pathname.substring(1));
Upvotes: 1
Reputation: 7157
You need to use a little regex syntax:
example\.com\/\w+
<script>
document.body.innerHTML = document.body.innerHTML.replace(/example\.com\/\w+/g, '');
</script>
Upvotes: 3
Reputation: 340
You can use regex like /example\.com\/\w+/
, \w+
match any alphanumerical continuous word.
Upvotes: 1