By default regcomp()
compiles a pattern as a so-called Basic Regular Expression; in such regular expressions the +
operator is not available. The regex syntax you're trying to use is known as Extended Regular Expression syntax. In order to have regcomp()
work with that more extended syntax you need to pass it the REG_EXTENDED
flag.
By the way, this comment:
As I also want to check for something like ^[BCD]+A$ which should match BBBA or CCCCA or DDDDA. Usage of ^[BCD][BCD]*A$ wont work for me as that could match BCCCA which is not the desired match
is based on a misconception of how the quantifiers +
and *
work. The regular expressions ^[BCD]+A$
and ^[BCD][BCD]*A$
are exactly equivalent.