This regular expressioncomes from JQuery, and the | means or, but which two parts are included to choose?
/^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/
Is it [^>]*$ | #([\w\-]*)$ or (<[\w\W]+>)[^>]*$ | #([\w\-]*)$) or something else?
This regular expressioncomes from JQuery, and the | means or, but which two parts are included to choose?
/^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/
Is it [^>]*$ | #([\w\-]*)$ or (<[\w\W]+>)[^>]*$ | #([\w\-]*)$) or something else?
Simply: x|y
Matches either x or y.
For example: /green|red/ matches green in green apple and red in red apple.
Writing it multiline with indentation helps:
^
(?:
[^#<]*
(
<
[\w\W]+
>
)
[^>]*
$
|
#
(
[\w\-]*
)
$
)
Your second guess is correct. The | has lower precedence than the concatenation (i.e. writing expressions after each other).
It's [^#<]*(<[\w\W]+>)[^>]*$ or #([\w\-]*)$, and both in a non-capturing group.
/^(?:EXP)$)/ # EXP => A|B
/^(?:A|B)$)/ # A => [^#<]*(<[\w\W]+>)[^>]*$, B => #([\w\-]*)$
/^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/