I am looking for a regex which would extract the intials from a string i.e.
str = "Doe, John L.L.M";
$str =~ /(^(\w)).*?((\s)(\w)).*?((\s)(\w))/;
$initial = $1.$2.$3;
print "$initial";
The above code is not serving my purpose.
String constants: There would be always 3 words (obvioulsy with 2 spaces in between) in the string however string may contain periods (.) and (,) in it. I am looking to extract.
Negation is probably easiest in the case that you know a word does NOT contain a space...
1. First Character of the string. 2. Next two Characters after space in the String.
#!/usr/local/bin/perl use strict; use warnings;
my $str = "Doe, John L.L.M";
if ($str =~ /^(\S)\S*\s(\S)\S*\s(\S)\S*/) { print "$2.$3.$1\n"; } else { warn "Pattern failed"; }
Doe, John L.L.M should be "DJL" Simth, G. M.D. should be "SGM"
Interesting order for initials, you will have to adjust mine back...
Any help, please?
HTH,
http://danconia.org
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>