On Fri, Oct 3, 2008 at 11:15 AM, Vyacheslav Karamov <[EMAIL PROTECTED]>wrote:
> Rob Coops пишет: > >> Try this: >> (?:Some text not captured) >> The ?: at the beginning tels perl that even though you want it to see >> thsi whole group you would not like perl to capture the string. >> Look up perlre (http://perldoc.perl.org/perlre.html) for some more >> information on this particulair topic it will lead you to the other pages >> that hold more information about more fun things you can do with regex's. >> Regards, >> Rob >> >> >> On Fri, Oct 3, 2008 at 10:52 AM, Vyacheslav Karamov < >> [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote: >> >> Hi All! >> >> I need to capture something in braces using regular expressions. >> But I don't need to capture wrong data: >> >> [Some text] - correct >> (Some text) - also correct >> [Some text) - wrong >> (Some text] - also wrong >> >> >> >> I was misunderstood. I need to capture something in braces (with braces or > not. Its not important), but > I need to capture if opening brace correspond closing one. > Ah, ok thats a different story in that case I would go for somethign along these lines: m/((.*?\)|\[.*?\])/ That should get you a match of (<as little stuff as possible in the middle>) or [<as little stuff as possible in the middle>] so only your first fwo lines should match the other two should not, the only thing that might trip you up is a line with multiple braces like [)](] will still be seen as matching if you want to exclude those you could do somehting along the lines of: m/((^\(.*?\])|(^\[.*?\)))/ which should also match the two top lines but will not match [)](] at least I believe it should not I have not tested it as I am being kept quite busy today (delivery deadline today)