'Lex program to count number of strings having ‘a’ as the second character

I wrote a program to count the number of strings having 'a' as the second character of the string. I tried using several patterns of the lex operators and also tried using the lex program start condition but none of them worked. This is the program that I wrote:

%{
  #include<stdio.h>
  #include<string.h>
  int count=0;
%}
%%
(^[a-z])/(a) {count++;}
%%
int yywrap(void){}
int main()
{   
  yylex();
  printf("\n%d strings with 'a' as second letter",count);
  return 0;
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source