in reply to Regular expressions: Extracting certain text from a line
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regular expressions: Extracting certain text from a line
by AnomalousMonk (Archbishop) on Apr 08, 2014 at 06:40 UTC | |
by kcott (Archbishop) on Apr 08, 2014 at 08:41 UTC | |
by AnomalousMonk (Archbishop) on Apr 09, 2014 at 01:23 UTC | |
by kcott (Archbishop) on Apr 09, 2014 at 03:08 UTC | |
by AnomalousMonk (Archbishop) on Apr 09, 2014 at 07:44 UTC | |
by AnomalousMonk (Archbishop) on Apr 08, 2014 at 16:59 UTC |