Question: `hello 'this' is my'str'ing`

If I have string like this, I'd like to make it all upper case if not surrounded by single quote. 

`hello 'this' is my'str'ing`=>`HELLO 'this' IS MY'str'ING`

Is there a easy way I can achieve this in node perhaps using regex?

Answer: 
You can use the following regular expression:

```
'[^']+'|(\w)

```

Here is a live example:

```js
var subject = "hello 'this' is my'str'ing";
var regex = /'[^']+'|(\w)/g;
replaced = subject.replace(regex, function(m, group1) {
    if (!group1) {
        return m;
    }
    else {
        return m.toUpperCase();
    }
});

document.write(replaced);
```

Credit of this answer goes to [`zx81`](https://stackoverflow.com/users/1078583/zx81). For more information see the [original answer](https://stackoverflow.com/a/23667311/3233827) of `zx81`.
Since Javascript doesn't support lookbehinds, we have to use `\B` which matches anything a word boundary doesn't match.

In this case, `\B'` makes sure that `'` isn't to the right of anything in `\w` (`[a-zA-Z0-9_]`). Likewise, `'\B` does a similar check to the left.

`(?:(.*?)(?=\B'.*?'\B)(?:(\B'.*?'\B))|(.*?)$)` ([regex demo](https://regex101.com/r/PI0LtL/2))

Use a callback function and check to see if the length of captures 1 or 3 is > 0 and if it is, return an uppercase on the match

\*\*The sample uses `\U` and `\L` just to uppercase and lowercase the related matches. Your callback need not ever effect `$2`'s case, so "Adam" can stay "Adam", etc.

---

**Unrelated, but a note to anyone who might be trying to do this in reverse. it's much easier to the the REVERSE of this:**

`(\B'.+?'\B)` [regex demo](https://regex101.com/r/PI0LtL/1)