bash – Composing a regex pattern from two short ones

I have a very long regex pattern that I want to split up into two parts. Would the following construct be the correct way to do this?

I want to match “## DN [TITLE]” followed by an number of comma separated keywords.

  dpn='[[:space:]]*([#;!]+|@c|//)[[:space:]]DN[[:space:]]\[.*\]'
  kpn='[[:space:]][^,]+((,[^,]+)*)*'

  lab=""
  lab="## DN [TITLE]"
  lab="## DN [TITLE] keyword"
  lab="## DN [TITLE] keyword,keyword"

  if [[ "$lab" =~ ^($dpn)($kpn)$ ]]; then
    echo "DN MATCH"
  else
    echo "DN NOMATCH"
  fi

My test fails upon using lab="## DN [TITLE]"

Read more here: Source link