Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Store regular expressions in a file.

by eff_i_g (Curate)
on Nov 11, 2010 at 15:48 UTC ( #870882=note: print w/replies, xml ) Need Help??


in reply to Re: Store regular expressions in a file.
in thread Store regular expressions in a file.

#!/usr/local/bin/perl use strict; use warnings; use String::Interpolate qw(safe_interpolate); # Read the regexes my @Rexes; while (my $t = <DATA>) { chomp $t; last if $t =~ /^$/; my ($regex, $repl) = split /\t+/, $t; push @Rexes, [ qr($regex), $repl ]; } # Process the text while (my $l = <DATA>) { $l=~ s/$$_[0]/safe_interpolate($$_[1])/eg for @Rexes; print $l, "\n"; } __DATA__ duck cluck a(b+)c \uc${1}\ua That bird says "duck!" xyzzy plugh ac abc abbc abbbc
That bird says "cluck!" xyzzy plugh ac CbA CbbA CbbbA

Replies are listed 'Best First'.
Re^3: Store regular expressions in a file.
by roboticus (Chancellor) on Nov 12, 2010 at 00:24 UTC

    ++eff_i_g:

    Sweet! I played with it for a while before giving up on the capture groups. I'll have to be sure to keep this handy!

    ...roboticus

Re^3: Store regular expressions in a file.
by yoda54 (Monk) on Nov 11, 2010 at 18:34 UTC
    Thanks everyone for the enlightenment!!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://870882]
help
Chatterbox?
[marto]: hey Corion, good weekend?
[prospect]: Thank you
[marto]: no problem prospect
[Corion]: I hope you all spent a good weekend!
[Discipulus]: good morning eumonks!
[Discipulus]: yes thanks, mostly at seaside, but the waterpolo tournemts went bad, very bad.. ;=(
[marto]: hey Discipulus, Corion a reasonable weekend. The boys first trip to the cinema
[Corion]: Discipulus: You got pushed too much under water?
[Corion]: marto: Oooh - cinema... I guess that's something I could do with my godson and sibling and sister as well, but I guess that getting a six year old and two four year olds into one movie is a tough sell ;)
[marto]: busy weekend, no me time :P

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2017-07-24 08:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (348 votes). Check out past polls.