You want to match either the start of the string ^ or after any newline \n character:
^
\n
mystr:match("^(%#+)") or mystr:match("\n(%#+)")
I don't think you can combine it into one match. Logical 'or' in Lua patterns?