Please help me understand the regular expression used in the solution of this problem:
function titleCase(str) {
return str.toLowerCase().replace(/(^|\s)\S/g, (L) => L.toUpperCase());
}
Particularly, this code:
(^|\s)
I understand what all three characters are used for: the caret, the pipe character, and the white space character. However, what I don’t understand is how the white space character in this instance is being used to denote characters or a string that occur after white space.
What I understand of the white space character from the relevant lesson is that it can be used to actually find white space, like spaces, tabs, return, etc. Does the existence of the pipe operator mean something other than “or”?