Example taken from Mozilla's help page
<script type="text/javascript">
re = /(\w+)\s(\w+)/;
str = "John Smith";
newstr = str.replace(re, "$2, $1");
document.write(newstr);
</script>
Is it possible to further manipulate the substring match directly in any way? Is there any way to, for example, capitalize just the word Smith in one line here? Can I pass the value in $2 to a function that capitalizes and returns a value and then use it directly here?
And if not possible in one line, is there an easy solution to turn "John Smith" into "SMITH, John"?
Trying to figure this out but not coming up with the right syntax.
Thanks.