Reputation: 338
I have this script used with a form (Credits to: Luka [./users/6634591])
<div class="center">
<form id="search">
<input type="text" id="keyword" />
<button type="submit">Search</button>
</form>
</div>
<script>
document.querySelector("#search").addEventListener("submit", urlMaker)
function urlMaker(event) {
let keyword = document.querySelector("#keyword").value;
let base = "https://www.example.com/list.php?q=";
let ending = "&dhd=1&hdd=low&dtt=list";
let url;
let url;
event.preventDefault();
url = base + keyword + ending;
window.location.href = url;
}
What I would like to do is parse the url string to replace certain characters and use like url.replace = Parsed value
I am pretty skilled at building regexes. Would it be possible to parse it through a regex function at that stage? PHP is not an option as I do want this to work without apache
Like always I have googled my eyes bleeding trying to find an answer before posting.
Thank you for any input!
Upvotes: 1
Views: 32
Reputation: 51914
You're looking for String.replace
which accepts a regular expression pattern.
Upvotes: 3