Fixing the || bug, refactoring the expression and commenting gives this:
use strict; use warnings; my $A = -4; my $w = 500; my $re = qr / ^\s* #Start of line followed by any amount of white space \Q$A\E #Litteral contents of $A \s* #Any amount of white space \*? #Optional * \s*cos #Any amount of white space followed by cos \s* #Any amount of white space ( #Start a capture group \s #At least one white space character \Q$w\E #Litteral contents of $w \s*t #Any amount of white space followed by t | #Match either expression (i.e. - with or without brackets) \(\s* #( followed by any amount of white space \Q$w\E #Litteral contents of $w \s*t #Any amount of white space followed by t \s*\) #Any amount of white space followed by ) ) #End of capture group \s+A #At least one white space character followed by A \s*$ /x; while (<DATA>) { print "Match: $_" if $_ =~ $re; } __DATA__ -4cos 500t A -4 cos 500t A -4*cos 500t A -4*cos(500t) A
In reply to Re: is there an easy way to dumb down this regular expression for me?
by GrandFather
in thread is there an easy way to dumb down this regular expression for me?
by moltar512
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |