Thanks. What if I added numbers like this
$msgText =~ s!(?<= )([a-z,0-9]+)(?= )!<bold>$1</bold>!g; But I didn't want a string of only numbers? In the strings I waned, I know the first character would not be a number. -----Original Message----- From: John W. Krahn [mailto:jwkr...@shaw.ca] Sent: Saturday, May 30, 2009 3:49 AM To: Perl Beginners Subject: Re: Matching Question Farrell, Patrick wrote: > This is roughly what I am trying to do. Surround lower case strings within a > string with tags. > > =========================================================== > $msgText="THIS IS MY test STRING"; > > $msgText =~ m/ [a-z]+ /; #or $msgText =~ /\s[a-z]+\s/; > > if(defined($1)){ That won't work correctly because 1) you have no capturing parentheses in your pattern, and 2) if the match failed $1 could be left over from a previous match. > $1=~ s/\s+//g; $1, like all the numeric variables, is READ-ONLY and cannot be modified. > $msgText =~ s/$1/ <bold>$1<\/bold> /; > } > > > Print "\n$msgText"; Perl is case sensitive so that should be: print "\n$msgText"; > ======================================================= > > > I get the following: > > THIS IS MY test STRING > > But I wanted expected this: > > THIS IS MY <bold>test<\/bold> STRING $ perl -le' my $msgText = "THIS IS MY test STRING"; print $msgText; $msgText =~ s!(?<= )([a-z]+)(?= )!<bold>$1</bold>!g; print $msgText; ' THIS IS MY test STRING THIS IS MY <bold>test</bold> STRING John -- Those people who think they know everything are a great annoyance to those of us who do. -- Isaac Asimov -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/