quick and easy one, i hope. i want to use the matching metacharacter '{}' to match a number of instances of a character, but i want to calculate that number "on the fly" (vs hard-coding a number, or creating a variable just for that regex). i'm not sure if i can do this, but here's what i tried, which fails:
if i use the commented out code, it works. it is no biggie if i have to create the variable first, but it just feels like there ought to be a way to do this. btw, i know there are betters ways to check for a two-digit number, this is just a simplified example of my problem.#!/usr/bin/perl use strict; use warnings; my $foo = shift || 12; my $i = 1; print "Is \`$foo' a two-digit number ... "; my $rc = ($foo =~ /^[0-9]{($i + 1)}$/) ? 'yes' : 'no'; #my $rc = ($foo =~ /^[0-9]{2}$/) ? 'yes' : 'no'; print $rc,"\n";
thanks.
In reply to Calculating variable {n} in regex match by atreyu
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |