Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I have an array of strings and I want to replace it with a new word, s +o I do this: $line='i got a dog and a bear.'; @a=('dog','bear','camel'); $a=join('|',@a); $line=~s/\b($a)\b/beast/g; say $line; Simply works, but the problem is that @a is not hard-coded, but instea +d inputted by the user. The elements in @a will contain special char +acters like | or . etc. How do I make this regex work with the antic +ipation of those characters?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regex - replacing an array of string
by Anonymous Monk on Dec 24, 2010 at 03:37 UTC | |
by Khariton (Sexton) on Dec 24, 2010 at 16:56 UTC |