ChOas has asked for the wisdom of the Perl Monks concerning the following question:
Fellow Celebates,
This should be simple, and I`m sure it CAN be done...Sad enough I`m also
sure that I haven`t been able to do it yet......
I want to apply a RegEx to a variable .. easy... BUT the RegEx resides
in a scalar...
Vars:
Good.. I had expected that...
Code2..n:
Match: none Pre: none Post: none
Match: none Pre: none Post: none
Match: none Pre: none Post: none
Match: none Pre: none Post: none
This is frustrating.. I`m just looking for code X (be it in an eval, or not, I don`t care)
that prints Match: A Pre: 1234 Post: 4321, given $String and $RegEx....
Any help would be very much appreciated...
GreetZ!,
print "profeth still\n" if /bird|devil/;
This should be simple, and I`m sure it CAN be done...Sad enough I`m also
sure that I haven`t been able to do it yet......
I want to apply a RegEx to a variable .. easy... BUT the RegEx resides
in a scalar...
Vars:
Code1:my $String="1234A4321"; my $RegEx="/a/i";
prints: Match: A Pre: 1234 Post: 4321{ $String=~/a/i; print "Match: ",$&||"none"," Pre: ",$`||"none"," Post: ",$'||"none","\ +n"; }
Good.. I had expected that...
Code2..n:
prints:{ $String=~$RegEx; print "Match: ",$&||"none"," Pre: ",$`||"none"," Post: ",$'||"none","\ +n"; } { eval $String=~$RegEx; print "Match: ",$&||"none"," Pre: ",$`||"none"," Post: ",$'||"none"," +\n"; } { eval { $String=~$RegEx; }; print "Match: ",$&||"none"," Pre: ",$`||"none"," Post: ",$'||"none"," +\n"; }
Match: none Pre: none Post: none
Match: none Pre: none Post: none
Match: none Pre: none Post: none
Match: none Pre: none Post: none
This is frustrating.. I`m just looking for code X (be it in an eval, or not, I don`t care)
that prints Match: A Pre: 1234 Post: 4321, given $String and $RegEx....
Any help would be very much appreciated...
GreetZ!,
- ChOas
print "profeth still\n" if /bird|devil/;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Applying a RegEx in a variable
by abstracts (Hermit) on Aug 10, 2001 at 13:51 UTC | |
by ChOas (Curate) on Aug 10, 2001 at 13:59 UTC | |
Re: Applying a RegEx in a variable
by Hofmator (Curate) on Aug 10, 2001 at 14:53 UTC | |
Re: Applying a RegEx in a variable
by George_Sherston (Vicar) on Aug 10, 2001 at 15:37 UTC | |
by Hofmator (Curate) on Aug 10, 2001 at 15:58 UTC | |
by George_Sherston (Vicar) on Aug 10, 2001 at 17:56 UTC | |
by Hofmator (Curate) on Aug 10, 2001 at 18:47 UTC | |
by George_Sherston (Vicar) on Aug 10, 2001 at 19:16 UTC | |
by ChOas (Curate) on Aug 10, 2001 at 16:22 UTC | |
by Hofmator (Curate) on Aug 10, 2001 at 16:37 UTC |
Back to
Seekers of Perl Wisdom