On 10/6/11 Thu Oct 6, 2011 4:05 PM, "Marc" <sono...@fannullone.us> scribbled:
> On Sep 8, 2011, at 10:13 AM, Rob Dixon wrote: > >> my $string = 'The Kcl Group'; >> >> $string =~ s/\b([aeiouy]{3,4}|[^aeiouy]{3,4})\b/\U$1/ig; >> >> print $string, "\n"; > > I'd like to revisit this, if I could. I've modified the above regex so as not > to capitalize ordinal numbers, however I've noticed that it produces incorrect > output if the word has an apostrophe. Given: > > my $string = "rex's chicken on 51st st. at lkj"; > $string =~ s/\b([aeiouy]{3,4}|[^aeiouy0123456789]{3,4})\b/uc($1)/eg; > > the output is: > Rex'S Chicken on 51st ST. at LKJ That is not what I get after cutting-and-pasting the above two lines into a Perl program. I get: rex'S chicken on 51st ST. at LKJ > > It should be: > Rex's Chicken on 51st St. at LKJ Why are Rex and Chicken capitalized here? They are not 3-4 letters strings consisting solely of vowels or consonants. > > I Googled and tried everything I'd found, but I can't fix it. Again, that > line should capitalize 3 and 4 letter words that have either all vowels or all > capitals. I think you mean "all vowels or all consonants" (not capitals). > The code I found below works great for capitalization except for > that one regex which throws a wrench into it. I am ignoring and deleting the complete program, as your problem seems to be with the regex. The problem is that the character class [^aeiouy0123456789] includes everything not listed, which includes all punctuation characters such as ''' and '.' (and also upper-case letters). Thus, 'st.' is matched by [^aeiouy0123456789]{3,4} and gets upper-cased. You should go back to your original character class of [bcdfghjklmnpqrstvwxz], which can be shortened somewhat as [bcdfghj-np-tvwxz]. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/