Alright folks. I am writing a bash script and would like compare a string against a regular expression containing a # using the =~ operator.
Here is what I have so far:
if [[ ${line} =~ \s*\# ]]; then
#do things
fi
As you can see, I am attempting to escape the # with a \, which is supposed to be possible according to this article. This is really confounding to me, however. My syntax highlighter is still highlighting the text following the # as if it were a comment.
Is my syntax highlighter incorrect? Will the escape of the # interfere with the parsing of the regex? Is there some way I can use quotes to avoid this issue?
#is never a shell comment character when it exists partway through a word, so your editor is really, really off here.