I am writing a regex to use with the GNU C regex library:
The string is of the form: (text in italics is a description of content)
(NOT a #) start (maybe whitespace) : data
I have written the following code, but it won’t match.
regcomp(&start_state, "^[^#][ \\t]*\\(start\\)[ \\t]*[:].*$", REG_EXTENDED);
What do I need to write?
examples:
to match:
state : q0
state: q0
state:q0s
not to match:
#state :q0
state q0
# state :q0
Thanks!
The pattern in your question was consuming the first letter in
statewith[^#], which left the match unable to proceed because it tries to matchtateagainst the pattern\(state\).You passed the flag
REG_EXTENDEDwhich means you don’t escape capturing parentheses but do escape literal parentheses.With regular expressions, say what you do want to match:
as in
Output: