PDA

View Full Version : Awk doesn't support lazy quantifers?



Arctic_Fox
June 27th, 2009, 12:09 AM
Hi guys, I tried to write an awk script which used the "*?" quantifier and found that it didn't work.


echo "ababbba" | awk '{ match($0,/a.*?a/); print RLENGTH}'

Should output 3 but outputs 7 instead. egrep behaves in the same way. Are there any linux utilities that do support lazy quantifiers?

ghostdog74
June 27th, 2009, 02:07 AM
Hi guys, I tried to write an awk script which used the "*?" quantifier and found that it didn't work.


echo "ababbba" | awk '{ match($0,/a.*?a/); print RLENGTH}'

Should output 3 but outputs 7 instead. egrep behaves in the same way. Are there any linux utilities that do support lazy quantifiers?

not everything have to solved with regular expression.


# echo "dsfsfabxsadfabbba" | awk -F"a" '{print length($2)+2}'
5

MadCow108
June 27th, 2009, 02:10 AM
perl regexp hast non greedy(lazy) quantifiers:
http://docstore.mik.ua/orelly/perl/cookbook/ch06_16.htm