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).
In reply to Re: Parsing Strings
by ww
in thread Parsing Strings
by doofus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |