Question: I need to replace `'http://'` with `'https://'` in a URL (if the former exists); and if `'http://'` or `'https://'` is not the prefix (schema), then I need to prefix the URL with `'https://'`.

I can simply check if the URL begins with `'http'` and prefix it to `'https'` accordingly or replace `'http'` if it exists. It's that simple and takes 2 lines of code, BUT...

Is it possible to do it with one line with a JavaScript regex function?

Answer: 
```js
function simpleHttpsPrefixer(url) {
    return url.replace(/^(?:https?:\/\/)?(.*)/, "https://$1");
}

```
Just do 

```
var str = "http://www.whatever.com.au";
str = str.replace("http://", "https://");
alert(str);

```

If you want to one-line it:

```
url = url.replace("http://", "https://");

```