On May 10, Dave K said:

>"Jeff 'Japhy' Pinyan" <[EMAIL PROTECTED]> wrote in message
>[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
>> On May 10, Dave K said:
>>
>> >while (<IN>) {
>> > if ( m/,$p1|$p2|$p3|$p4|$p5|$p6|$p7|$p8,/ ) {
>>
>> You need ()'s around the $p1|$p2|... part.  The regex
>>
>>   /,abc|def|ghi,/
>>
>> is not the same as
>>
>>   /,(abc|def|ghi),/
>>
>> Do you see why?
>
>No I don't see why I need (). (but I do see an opportunity to learn
>something...). The kludge I posted does work (with the sample data in the
>original post).  Why would () be required? If I understood the post
>correctly the task did not require capturing any numbers.

The OP wanted to match any of a set of numbers, BETWEEN COMMAS.  Let's use
a much smaller example.  Here's my data:

  11453,342,65788
  49384,523,48493
  00120,148,98233

If I want to see what lines have 342, 484, or 823, BETWEEN COMMAS, I need
a regex like

  /,(342|484|823),/

or

  /,(?:342|484|823),/

You need to group them together.  If you don't, you get

  /,342|484|823,/

which means "match ',324' or '484' or '823,'", so you would get false
matches.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to