G'day Wcool,
You get the output:
MATCH = [](EntityName$ = DERIVED_ATTRIBUTE_TABLE, FieldNames$[]
because
So, instead of matching any character one or more times non-greedily (i.e. '.+?'), what you really want is to match any character that isn't ']' one or more times greedily (i.e. '[^\]]+').
You get the ouput:
MATCH = {} = { this is a test }
for much the same reasons. The fix is similar, changing '.+?' to '[^}]+'.
Also, unless you really want those extra captures, you can lose the two inner pairs of parentheses.
Here's my test:
#!/usr/bin/env perl -l use strict; use warnings; my $line = 'EntityMappingFetchByName?[](EntityName$ = DERIVED_ATTRIBUT +E_TABLE, FieldNames$[] = [ USER_ENTITY_NAME ], text${} = { this is a +test }), line 6'; my $re = qr< ( { [^}]+ } | \[ [^\]]+ \] ) >x; print "MATCH = $1" while $line =~ /$re/g;
Output:
MATCH = [ USER_ENTITY_NAME ] MATCH = { this is a test }
-- Ken
In reply to Re: Regular expressions: Extracting certain text from a line
by kcott
in thread Regular expressions: Extracting certain text from a line
by Wcool
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |