Programming
Memory App
Regex



Non-capturing






Regex matches m/../

Perl uses regex in many ways, the simplest being to check if a regex matches text held in a variable. The m/../ surrounding the regex tells Perl what to do with it. The surrounding ^$ ensures that the entire $phone contains only digits. $phone = "0728824242"; if ($phone =~ m/^[0-9]+$/) { print "only digits"; }

Non-capturing parentheses

Perl, and some other regex flavors, do provide a way to do this. You can use the special notation (?: ), which group but do not capture. This use of "?:" has no relation to the optional ? metacharacter. The benefits of this are twofold. The match process is more efficient, and may be less confusing later to someone reading the code.. $temp = "-98.6 F"; if($temp =~ m/^([-+]?[0-9]+(?:.[0-9]*)?) (?:[CF])$/) { print "n $1"; #-98.6 print "n $2"; #nothing - not captured print "n $3"; #nothing }
Comments
Comments ...