Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Applying a RegEx in a variable

by abstracts (Hermit)
on Aug 10, 2001 at 13:51 UTC ( #103816=note: print w/replies, xml ) Need Help??


in reply to Applying a RegEx in a variable

Hello

Try reading in perlop about the qr operator. Here is an example about how it can be used:

my $String="1234A4321"; my $RegEx=qr/a/i; $String =~ $RegEx; print "Match: ",$&||"none"," Pre: ",$`||"none"," Post: ",$'||"none","\ +n"; # Match: A Pre: 1234 Post: 4321
Hope this helps,,,

Aziz,,,

Update: Yes, you got the right idea there using

$re = eval "qr$regexp_val";
Make sure you trust the source of your regexp before feeding it to eval.

Replies are listed 'Best First'.
Re: Re: Applying a RegEx in a variable
by ChOas (Curate) on Aug 10, 2001 at 13:59 UTC
    Hmmmmmm.....Actually....no ;))

    I have no influence over the regex, it could come
    from a file, or from user input... it`s really a
    scalar...

    BUT!..... I can do
    my $Tmp="/a/i"; my $RegEx=eval "qr$Tmp";
    For wich I can build a working construct... hmmmm...
    I`m going to explore this a bit more....
    So actually it DID help!! .....Thanks! ;)))

    ... A little bit later ...

    Hmmmmm.... maybe it didn`t help... I`ll try some more ;))

    ... A little bit more later ...

    Okay.. I got it to work!! cheer!!... I`ll post the code where
    it`s going to be in hopefully next week.... thanks!!

    GreetZ!,
      ChOas

    print "profeth still\n" if /bird|devil/;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://103816]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2021-03-04 06:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (98 votes). Check out past polls.

    Notices?