Reputation: 5911
How to match aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab where number of a's should be min of 10?
I mean i know this way:
[a][a][a][a][a][a][a][a][a][a][a][a][a]a*b
But there must be a better elegant method where is if my min number of a's become say 100..
What is it? I am trying to match (a^n)b sort of thing where n can be anything
EDIT:
I forgot to mention this is done using lex and yacc.. where the lex has to return a token to yacc.
%{
#include "y.tab.h"
%}
%%
aaaaaaaaaa[a]*b {return ok;}
\n {return '\n';}
. {return 0;}
%%
Upvotes: 0
Views: 141
Reputation: 11669
If your lex
is flex, you can use a{10,}
.
If not so, according to
3. Lex Regular Expressions
, you can use a{10}a*
instead.
Upvotes: 2
Reputation: 13574
Footy,
[WARNING: This answer is COMPLETE BUNKUM!!!]
(if you mean soccer, we're swarn enemies ;-)
Ummm, No... That is not as far as I know, using "the standard" regular expression syntax as supported by sed, grep, nawk, and the likes... and no not even egrep... As far as I know, the a{10,*}
syntax (which is exactly what you're hankering for) didn't emerge until Perl rewrote all the books on the capabilities of regular expressions... and (don't quote me on this) I don't think that happened until like version 5.
So yeah, If you're stuck with using nawk, then it's the aaaaaaaaardvarking hardway dude. Sorry.
Cheers. Keith.
EDIT:
Hmmm... I seem to be the odd-man-out here... maybe everone-elses "standard operating environment(s)" have been updated with "standard tools" that recognise later regular expression syntax extensions... Sooo... Hmmm... I tested this on my (three year old) cygwin implementation of egrep... and it suprised me by actually working!!!
Administrator@snadbox3 ~
$ egrep 'a{3,}b' <<-eof
> ab
> aab
> aaab
> aaaab
> eof
aaab
aaaab
So I'm WRONG all ends up... looks like the "new" {min,[max]}
syntax is reasonably well supported, and I'm getting old. Sigh.
Cheers. Keith.
Upvotes: 1
Reputation: 3411
use this format : a^na*b
and replace n with any number you want.
Upvotes: -1
Reputation: 420971
Try
a{10,}
which says a
10 or more times.
grep -E "a{10,}" filename
matches aaaaaaaaaaaaaaaaaaaaaaaaab
but not aaaaaaaaab
.
Upvotes: 7