--- James Edward Gray II <[EMAIL PROTECTED]> <snip> > > And this one I'd think should be $3, and match > Steal > > or Assist etc., but the results don't say that. > > > > (?:Steal|Assist|Block|replaced by) > > Stuart, I love your questions. ;) You're always > missing one tiny > piece of knowledge and you always ask them in such a > way that I know > exactly what it is. Here's the missing piece this > time: > > You see that the above is surrounded by ( ) and you > think that means it > should capture. The truth is that the above is > surrounded by (?: ), > which happens to be ( )'s cousin. It groups things > together, like ( ), > but it does not capture. I had to cluster them so > the |s would work, > but I didn't need to hang onto the results, so I > chose (?: ) over ( ). > > You could do it just fine with normal parenthesis, > if you prefer. If > you do, you just have to remember that your third > answer is in $4, > because $3 is holding some junk. Take your pick. >
Geez, I can't recall them covering (?: ) in my books...D'oh! The part about it grouping and capturing things makes sense, as it's the "cousin" of ( ). The part about being able to include the |'s doesn't. I found out, without knowing at the time, that the parentheses breakdown with |'s. I didn't know it at the time, but when I put the ORs in the parentheses and ran the program, I just got the command prompt, no output. Your explanation tells me that (?: ) could capture the ORs, and implies that the ( ) could not. <--This part makes sense, as i'll just regard it as a rule. But then you go on to say that I could still use it with ( ), but then $3 would contain junk and $4 would contain the name after the (?:Steal|Assist|Block|replaced by). I'm assuming that junk in $3 would be either Assist or Block or Steal or replaced by, is that correct? I ask this because later, perhaps two days from now, perhaps two weeks from now, I'm going to want that information, assuming it is Assist or Block or Steal or replaced by. Do I just put (:? ) within ( )? That sortof makes sense, but it also seems, I'm not sure what the right word is, but it doesn't seem right. Lastly, I'm curious about this (:? ) operator. I'm going to look it up, but assuming that perldoc is not going to explain it sufficiently for me, as is often the case, do you mind telling me why it is needed to get the |'s, if that also applies to &, and numerical and word comparison operators? Thanks. > > Instead, $3 is this, and matches the second name. > > (\w+) > > > > If backreferences are supposed to be in > parentheses, > > why isn't this > > (?:Steal|Assist|Block|replaced by) > > a backreference? > > I'm hoping this makes sense now. There are only > three captures in my > regex. (\w+) is the third. Can you see that now? > It does, and I can. Oh, and I appreciate when you not only answer a question with an explanation, but you use an example as well. That's extremely helpful. -stu > James > __________________________________ Do you Yahoo!? Yahoo! Search - Find what you’re looking for faster http://search.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>