To learn how to do it by hand, you can simply break it down like this (this is a task that will surely help you in the future):
var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,
The first part is to know how a regex is generally written, so in this case it would be:
var variableName = /stuff/g;
^ ^ ^^
delimiters/---+--/|
| |
regex / \global modifier, can also have a case modifier
So let's strip away the modifier and the start and end and evaluate just the regex:
((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)
Still gobbledygook, but let's continue: The regex is for capturing content and we know that unescaped (meaning they use a backslash before the character being escaped \
) parenthesis are capturing braces, let's add some newlines around each parenthesis (only for the purposes of examination!!!) and pipes mean "or"
(
(?:
\(
(?:
\(
[^()]+
\)
|
[^()]+
)+
\)
|
\[
(?:
\[[^\[\]]*\]
|
['"][^'"]*['"]
|
[^\[\]'"]+
)+
\]
|
\\.
|
[^ >+~,
(
\[\\]+)+
|
[>+~]
)
(\s*,\s*)?
(
(?:
.
|
\r
|
\n
)*
)
Square braces mean "selectively match what is inside of this as any value from a choice-set" and so now I'm going to add a few comments, and let you work out the rest (also, it does look like some parens are missing)
(
(?: //<-- start a non-capturing group (means, don't tell the app we matched)
\(
(?: //<-- start a non-capturing group (means, don't tell the app we matched)
\(
[^()]+ //one or more paren pairs inside a paren pair
\)
|
[^()]+ //or one or more paren pairs
)+
\)
|
\[
(?:
\[[^\[\]]*\]
|
['"][^'"]*['"]
|
[^\[\]'"]+
)+
\]
|
\\.
|
[^ >+~,
(
\[\\]+)+
|
[>+~] //either a tilde, plus or opening brace
)
(\s*,\s*)?
(
(?:
.
|
\r
|
\n
)*
)