You used (...)(a capture group ) instead of [...](a character class ). Use a character class:
^^^^^^^^^^^^^
See regex demo (note that most capture groups are redundant here, and I deleted them. In addition, the .literal dot must be escaped.)
[A-Za-z0-9_]+matches 1 or more letters, numbers or _.
(A-Za-z0-9_)+ 1 A-Za-z0-9_ (. ).
, Java \w [A-Za-z0-9_]
#+ +\w+\.sh +
, \ Java (String pattern = "#+ +\\w+\\.sh +#+";).