hi,
thank you for your solution which works perfect for the data i have
given.
the trouble is: my data looks a little more complex as I have lots of
accented characters so with your code I need to specify each of those
characters in the tr/// part. I reckon the other way around would be
more usefull: speceifying all characters that can be irgnored for
matching. Is there any chance of doing this?
And a second small issue: is it possible to change the code so that
not only full words are marked by the double ##-characters but also
parts of it, e.g. searching for 'ooba' would result in
f[##o]o(ba##r)  ?
again, thanks for any ideas and hints,
Frank


On 9 Aug., 02:34, jwkr...@shaw.ca ("John W. Krahn") wrote:
> 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/


Reply via email to