in reply to Parsing Strings
Not stupid -- except (some would argue) for the failure to use strict, warnings and some prints -- and clumsy (IMO) only in your indentation.
That said, the following seems to be what you want. More commentary follows:
#!/usr/bin/perl -w use strict; use 5.018; # 1157516 my $sp = ".A(~(B & C & ( D | (E & F) ))),"; # $pin = string between . and ( if ( $sp =~ /\.(.*?)\(/ ) { my $pin = $1; say "|-- $pin --|\n"; } my $sig; # if ( $sp =~ /\((.*?)\)/ ) { if ( $sp =~ /\( (.*?\){2}) .*/x ) { $sig = $1; } say "\t|-> $sig <-|";
The /x modifer isn't necessary; it merely makes it easier to read the second regex; the use of the quantifier lets the regex capture all but the last ")" (the space between the one which trails "F" before the 3 parens leaves the one after the "F" out of consideration).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Parsing Strings
by doofus (Acolyte) on Mar 14, 2016 at 18:59 UTC | |
by ww (Archbishop) on Mar 14, 2016 at 21:01 UTC | |
by doofus (Acolyte) on Mar 14, 2016 at 22:57 UTC | |
by ww (Archbishop) on Mar 15, 2016 at 04:11 UTC |