If you want to match the whole source text, the regex must start with ^
and end with $
(anchors).
To match /
use just /
. In some other host languages (e.g. Javascript or Perl)
slashes are used as regex delimiters, so to use the slash as the content
of regex, you would have to escape it with a backslash, but in go this is not needed.
To match *
use \*
. You can not use just *
(as Volker proposed), because it is a quantifier, meaning 0 or more.
As you want to match the whole string (not just /*
), the next part
should be .*
(any number of any chars).
If you want to catch the "rest" of string in a capturing group, surround
this part with parentheses.
And the last step of complication: Usually after /*
there are some spaces
and only after them the fragment you actually want to catch. In such case:
- start from
\s*
(optional sequence of white chars),
- then put
(.*)
.
So the final solution is: ^/\*\s*(.*)$
For a working example see https://regex101.com/r/80ORab/1
Edit
If you write your regex as a string, in double quotes, the backslash
must be written twice.