Regex doesn't check for end of line
Special characters such as
do not have the same meaning within a character class. In a character class, they are just characters, so
will match a space character or a character
. It won't match the end of the line.
If you want to match a space character or the end of a line, you must use alternation, i.e.
source to share