Link to home
Create AccountLog in
Avatar of onyourmark
onyourmark

asked on

regular expression question

Hi. I am trying to filter out lines with just a few words (6 words or less) and this can also include lines like
1:13  Add to Added to queue
or
Tokio Hotel - Automatic
or
n0547 to n0549 queue for

I tried this but this is not exactly right

next if (($record =~ m{^\s*\w*\d*\s*\w*\d*\s*\w*\d*\s*\w*\d*$}));

Any other suggestions?
Thank you.
Avatar of ozo
ozo
Flag of United States of America image

print "6 words or less" if (()=$record =~/\b\w+\b/g) <= 6;
# Or maybe
 print "6 words or less" if (()=$record =~/\S+/g) <= 6;
depending on what you count as a word
Avatar of onyourmark
onyourmark

ASKER

Thanks. Using what you said,
would this work

next if (($record =~ m{/\b\w+\b/g}));
next if (($record =~ m{/\b\w+\b/g}));
will skip records with 1 word or more
next if (($record =~ m{/\b\w+\b/g}) <= 6);

Will that skip lines with 6 or fewer words?
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Thanks very much.