Frank Müller wrote:
dear all,
Hello,
i want to make some search and replace within a string where I can
define a set of characters, especially parenthesis, brackets etc.,
which are to be ignored.
For example, I have the following string:
sdjfh sdf sjkdfh sdkjfh sdjkf f[o]o(bar) hsdkjfh sdkljfhs sjfh sdkj
sdjkfh sdjfh ska
A search and replace for 'foobar' should result in the following
string:
sdjfh sdf sjkdfh sdkjfh sdjkf ##f[o]o(bar)## hsdkjfh sdkljfhs sjfh
sdkj sdjkfh sdjfh ska
$ perl -le'
$_ = "sdjfh sdf sjkdfh sdkjfh sdjkf f[o]o(bar) hsdkjfh sdkljfhs sjfh
sdkj sdjkfh sdjfh ska";
print;
s{ ( \S+ ) }{ ( $x = $1 ) =~ tr/a-zA-Z//cd; "foobar" eq lc $x ? "##$1##"
: $1 }xeg;
print;
'
sdjfh sdf sjkdfh sdkjfh sdjkf f[o]o(bar) hsdkjfh sdkljfhs sjfh sdkj
sdjkfh sdjfh ska
sdjfh sdf sjkdfh sdkjfh sdjkf ##f[o]o(bar)## hsdkjfh sdkljfhs sjfh sdkj
sdjkfh sdjfh ska
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/