On Tue, 2002-09-10 at 03:32, [EMAIL PROTECTED] wrote: > Hello, All: > > How can I capture all the words that contain 'at' in the string 'A fat cat > sat on my hat.'? > > Any pointers? > > $sentence = 'A fat cat sat on my hat.' > $sentence =~ m/(\wat)/; > > ....returns: > > $1 = 'fat' > > -- > Eric P. > Sunnyvale, CA > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > >
You were on the right track, but you need to do global matching and define "contains" better. Here is what I would do. <snip href="perldoc perlop"> The "/g" modifier specifies global pattern match ing--that is, matching as many times as possible within the string. How it behaves depends on the context. In list context, it returns a list of the substrings matched by any capturing parenthe ses in the regular expression. If there are no parentheses, it returns a list of all the matched strings, as if there were parentheses around the whole pattern. </snip> <code> #!/usr/bin/perl my $str = 'A fat cat sat on my hat and attacked me.'; my @at_words = $str =~ /(\w*at\w*\b)/g; print "@at_words\n"; </code> <output> fat cat sat hat attacked </output> -- Today is Pungenday the 34th day of Bureaucracy in the YOLD 3168 Or not. Missile Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]