RE: regular expression in a variable




You're not being very clear what it is you're trying to do. I can see
two ways of interpreting this.

Regular expressions are mostly for checking the format of text to see if
certain conditions "match". You might be asking how to do this:

########################

use strict;
use warnings;
opendir(DIR,".") or die("Couldn't open the current directory!\n");
my @files = readdir(DIR);
foreach my $file(sort @files){
if($file =~ /(.*test.*)/i){
print "MATCH: $file\n";
}
}

#########################

You can also use the $1 variable to capture the last text string that
matched the part of the regular expression between the parentheses.


If, on the other hand, you're trying to generate file names, then
regular expressions aren't what you're looking for.

my $prefix = "123";
my $postfix = "456";
my $filename = $prefix."test".$postfix;
print $filename."\n";




-----Original Message-----
From: Curt Shaffer [mailto:cshaffer@xxxxxxxxx]
Sent: Tuesday, February 28, 2006 12:20 PM
To: beginners@xxxxxxxx
Subject: regular expression in a variable

I need to set a variable to a filename where only 1 section of the file
is
static.

For example:

$filename =~ /test/;

Where the following:

Print "$filename\n";

Would produce:

123test456.txt


.



Relevant Pages

  • Re: Serious Perl Regular Expression deficiency?
    ... I started doing Perl 2 years ago and have ... > conclusion that regular expressions have a serious ... This is serious because the not string ... If you want to pull out the contents of XML comments you could do this. ...
    (comp.lang.perl.misc)
  • Re: Remove characters from string
    ... and your link took me to the templates page at microsoft office. ... there expaining regular expressions unless you meant I should search for it. ... | them to the same format for ease of processing. ... | the string I remove extraneous characters. ...
    (microsoft.public.excel.programming)
  • Re: dividing an replacing spaces in string
    ... I knew regular expressions would help in this. ... This newly delimited string will dump into separate rows like this ... Dim colMatches As Object ... Set objRe = CreateObject ...
    (microsoft.public.excel.programming)
  • Re: combining millions of different regular expressions
    ... match a given string with all of them some how. ... merged state machine will have an optimal structure to improve the ... First, be careful with what you mean by matching regular expressions, ... (One of those cases where theory and practice mis-align.) ...
    (comp.theory)
  • Re: Extract email addresses
    ... Because of a difference in the VBA flavor of Regular Expressions, ... Function REMid(str As String, Pattern As String, _ ... Dim objRegExp As RegExp ...
    (microsoft.public.excel.worksheet.functions)