Careful what you wish for...
Here's a couple of good resources for learning the basics:
https://www.shortcutfoo.com/app/dojos/regex/cheatsheethttps://cheatography.com/davechild/cheat-sheets/regular-expressions/To fix that particular case, you can just add the dash inside the square brackets:
Regex([Vocalist(s)],/#([\w\s\.\-]+(?=\s\())#/, -2)
A more flexible Regex would be this one (capture anything until it finds a "(" or reaches the end of the text):
regex([Vocalist(s)],/#(.+?)\s*[\($]#/, 1)
Here's a breakdown of the first regex:
\w = any word char: A to Z, a to z, underscore
\s = whitespace
\. = the dot character (backslash is the escape character; just the dot "." means "any character", but "\." means the dot character literally.
\- = the dash character, also need escaping when used inside ranges [ ... ]
[\w\s\.\-] = a range - matches one of the 4 above
[\w\s\.\-]+ = match any of those chars 1 or more times (plus)
(?= ... ) = "followed by"; this is called a positive lookahead; it means that the next text needs to match this, but it won't be included in the output
\( = open parenthesis symbol, escaped. Same as the dot above, the "(" is special so needs to be escaped
(?=\s\() = "followed by" a space and an open-parenthesis
So the full expression is:
([\w\s\.-]+(?=\s\()) = letters, spaces, dot or dash, one or more times, which are followed by a space and a parenthesis.
Note that this won't work if the [Vocalist(s)] has no open-parenthesis, since the lookahead won't find anything to match.
The other one is:
.+ = any character, one or more times
(.+) = these parenthesis make this a "capture" group. The last arg in the Regex() function ("1") specifies which capture group we want for the output.
\s* = whitespace characters, 0 or more times. Meaning, an optional space
[ ... ] = again a range, matches one of the chars inside
$ = end of string position (not a literal char)
[\($] = matches an open-parenthesis, OR the end of the string (meaning, the parenthesis is optional too!)
To sum it up:
(.+)\s*[\($] = any number of characters which are *optionally* followed by spaces, open parenthesis, or nothing.