use strict; use warnings; use YAPE::Regex::Explain; my $regexp = qr/^(.*?)((=<)|[<=>])(.*)/; my $exp = YAPE::Regex::Explain->new($regexp); print $exp->explain; #### NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- ^ the beginning of the string ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- .*? any character except \n (0 or more times (matching the least amount possible)) ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- ( group and capture to \2: ---------------------------------------------------------------------- ( group and capture to \3: ---------------------------------------------------------------------- =< '=<' ---------------------------------------------------------------------- ) end of \3 ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- [<=>] any character of: '<', '=', '>' ---------------------------------------------------------------------- ) end of \2 ---------------------------------------------------------------------- ( group and capture to \4: ---------------------------------------------------------------------- .* any character except \n (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \4 ---------------------------------------------------------------------- ) end of grouping ---------------------------------------------------------------------- #### my $re = qr{ ^(.*?) ( (=<) | [<=>] ) (.*) }x; #### my $re = qr{ ^ # Beginning of line \s* # Optional whitespace ([a-zA-Z0-9_]+) # Capture(1) Alphanumeric LHS \s* # Optional whitespace ( # Capture(2) either: [<>!]= # <=, >=, != | [<>=] # <, >, = ) \s* # Optional whitespace ([a-zA-Z0-9_]+) # Capture(3) Alphanumeric RHS }x; #### my $operand = '[a-zA-Z0-9_]+' ; my $re = qr{ \A # Beginning of line \s* # Optional whitespace ($operand) # Capture(1) Alphanumeric LHS \s* # Optional whitespace ( # Capture(2) either: [<>!]= # <=, >=, != | [<>=] # <, >, = ) \s* # Optional whitespace ($operand) # Capture(3) Alphanumeric LHS }x; #### use strict; use warnings; my $operand = '[a-zA-Z0-9_]+' ; my $re = qr{ ^ # Beginning of string \s* # Optional whitespace ($operand) # Capture(1) Alphanumeric LHS \s* # Optional whitespace ( # Capture(2) either: [<>!]= # <=, >=, != | [<>=] # <, >, = ) \s* # Optional whitespace ($operand) # Capture(1) Alphanumeric LHS }x; while (my $line = ) { my ($lhs,$operator,$rhs) = $line =~ $re; if ($line =~ $re) { my ($lhs,$operator,$rhs) = ($1,$2,$3); printf " (%4s) (%2s) (%4s)\n", $lhs, $operator, $rhs; } } __DATA__ a=b a!=b ab a=>b a=