What does the '|' (pipe character) mean in a regular expression? [duplicate]

Solution 1:

It's [^#<]*(<[\w\W]+>)[^>]*$ and #([\w\-]*)$

Regular expression visualization

Debuggex Demo

Solution 2:

Simply: x|y

Matches either x or y.

For example: /green|red/ matches green in green apple and red in red apple.

See regular expression on mdn

Solution 3:

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).