For the sake of an answer:
string-match is meant for to be used with regexps.
(string-match REGEXP STRING &optional START)
Return index of start of first match for REGEXP in STRING, or nil.
Matching ignores case if ‘case-fold-search’ is non-nil.
If third arg START is non-nil, start search at that index in STRING.
For index of first char beyond the match, do (match-end 0).
‘match-end’ and ‘match-beginning’ also give indices of substrings
matched by parenthesis constructs in the pattern.
You can use the function ‘match-string’ to extract the substrings
matched by the parenthesis constructions in REGEXP.
Here are some examples
(string-match "\\(dog\\|cat\\)" "There is a dog.") ;; => 11
(string-match "\\(dog\\|cat\\)" "There are two cats here." 0) ;; => 14
(string-match "\\(dog\\|cat\\)" "There are two cats here." 15) ;; => nil
(string-match "\\(dog\\|cat\\)" "There are horses.") ;; => nil
Note that if you don't plan on using
match-data after using
string-match you should prefer to use
string-match-p which works just like
string-match except that it doesn't modify
match-data when run.
As other have said, in your case
looking-at would probably be a better choice anyway.
Return t if text after point matches regular expression REGEXP.
This function modifies the match data that ‘match-beginning’,
‘match-end’ and ‘match-data’ access; save and restore the match
data if you want to preserve them.