in reply to Bidirectional Regular Expression Parsing and Matching Text Generation?
And then:package MatchRegex; use strict; use vars qw( @ISA @EXPORT_OK @digits @alpha ); require Exporter; @ISA = 'Exporter'; @EXPORT_OK = qw( digits alpha UCalpha LCalpha ); @digits = (0..9); @alpha = ('a'..'z', 'A'..'Z'); sub digits { ref $_[0] and local @digits = @{shift()}; # could use my() my $len; if (!@_) { $len = 1 } elsif (@_ == 1) { $len = $_[0] } else { $len = $_[0] + rand($_[1] + 1 - $_[0]) } return map $digits[rand @digits], 1 .. $len; } sub LCalpha { local @alpha = @alpha[0..25]; α } sub UCalpha { local @alpha = @alpha[26..51]; α } sub alpha { ref $_[0] and local @alpha = @{shift()}; # could use my() my $len; if (!@_) { $len = 1 } elsif (@_ == 1) { $len = $_[0] } else { $len = $_[0] + rand($_[1] + 1 - $_[0]) } return map $alpha[rand @alpha], 1 .. $len; }
This is a glorified "make a random string as per my request" module. It can be expanded. But it can't interpret your regex for you. That's left up to you. Maybe MJD or Ilya or someone else could help hack at the regex engine to make something like this more likely.use MatchRegex qw( digits UCalpha ); $filename = join "", ( digits(2), # \d{2} UCalpha(2,5), # [A-Z]{2,5} '_', # _ digits(2), # \d{2} digits(2), # \d{2} digits(4), # \d{4} );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: Bidirectional Regular Expression Parsing and Matching Text Generation?
by japhy (Canon) on Oct 24, 2000 at 18:25 UTC |