Regex Match Anything Except Character Link to heading

# match string starting with #, followed by anything not white space
rg "^#[^\s]+"

# match string starting with #, followed by anything not white space or other #
rg "^#[^\s|#]+"