Click here to get back home

match pattern "not"

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
match pattern "not" Ela 06-26-2008
---> Re: match pattern "not" Erwin van Koppe...06-26-2008
| `--> Re: match pattern "not" Jens Thoms Toer...06-26-2008
Posted by Ela on June 26, 2008, 9:20 am
Please log in for more thread options
how to replace a line's all characters (case-insensitive) NOT equal to any
of say, [ABCDE] to K?

e.g.

I am the sunny boy.

to

KKaKKKKeKKKKKKKbKKK



Posted by Erwin van Koppen on June 26, 2008, 9:26 am
Please log in for more thread options

>
> how to replace a line's all characters (case-insensitive) NOT equal to any
> of say, [ABCDE] to K?
>
> e.g.
>
> I am the sunny boy.
> to
> KKaKKKKeKKKKKKKbKKK

Assuming you mean lower case [abcde], you can do it like this:

$a = 'I am the sunny boy.';

($b = $a) =~ s/[^abcde]/K/g;

print "$b\n";

KKaKKKKeKKKKKKKbKKK




Posted by Jens Thoms Toerring on June 26, 2008, 9:45 am
Please log in for more thread options

> >
> > how to replace a line's all characters (case-insensitive) NOT equal to any
> > of say, [ABCDE] to K?
> >
> > e.g.
> >
> > I am the sunny boy.
> > to
> > KKaKKKKeKKKKKKKbKKK

> Assuming you mean lower case [abcde], you can do it like this:

> $a = 'I am the sunny boy.';

> ($b = $a) =~ s/[^abcde]/K/g;

> print "$b\n";

And to make it case-insensitive just add 'i' to the match flags:

($b = $a) =~ s/[^ABCDE]/K/gi;

Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de

Posted by Mirco Wahab on June 26, 2008, 9:47 am
Please log in for more thread options
Ela wrote:
> how to replace a line's all characters (case-insensitive) NOT equal to any
> of say, [ABCDE] to K?
> I am the sunny boy.
> to
> KKaKKKKeKKKKKKKbKKK

use the 'tr' operator:

my $text = 'I am the sunny boy.';
$text =~ tr/a-e/K/c;

(http://perldoc.perl.org/perlop.html)

Regards


M.

Posted by Jürgen Exner on June 26, 2008, 12:52 pm
Please log in for more thread options
>how to replace a line's all characters (case-insensitive) NOT equal to any
>of say, [ABCDE] to K?

perldoc perlop --> tr/// --> option c:
        c Complement the SEARCHLIST.

>I am the sunny boy.
>
>to
>
>KKaKKKKeKKKKKKKbKKK

But your text didn't contain any of [ABCDE], so every single character
should be 'K', shouldn't it?

jue

Similar ThreadsPosted
pattern match July 26, 2005, 3:42 pm
pattern match March 20, 2008, 1:29 am
match pattern ********* August 3, 2008, 4:34 am
pattern match with newline July 27, 2004, 9:07 pm
Use of uninitialized value in pattern match (m//) October 19, 2005, 7:58 am
use of uninitialised value in pattern match (m//) May 17, 2006, 12:21 am
Use of initialized value in pattern match May 18, 2006, 2:10 pm
Problem with pattern match March 8, 2007, 10:07 am
match string by re using some pattern July 25, 2007, 9:44 am
Match repeating pattern September 8, 2007, 2:41 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap