Wcool has asked for the wisdom of the Perl Monks concerning the following question:
Hi Perl Monks,
Hi Perl Monks,
A program I am working on is parsing text to extract anything enclosed in curly or straight brackets. However it should not extract {} or [] (empty enclosures)
For instance if the input line is:
should return "[ USER_ENTITY_NAME ]" and "{ this is a test }" only. When I use this pattern:EntityMappingFetchByName?[](EntityName$ = DERIVED_ATTRIBUTE_TABLE, Fie +ldNames$[] = [ USER_ENTITY_NAME ], text${} = { this is a test }), lin +e 6
((\{.+?\})|(\[.+?\])) in a while loop
I get:
MATCH = [](EntityName$ = DERIVED_ATTRIBUTE_TABLE, FieldNames$[] MATCH = [ USER_ENTITY_NAME ] MATCH = {} = { this is a test }
Whatever I try, the expression always seems to be greedy. How do I make the expression not greedy and skipping empty {} and []?
Thanks for your answers
|
---|
Back to
Seekers of Perl Wisdom