Dear John,

Thank you very much for you help. One more small help.

fourth string

B. van Sures to be tagged as <fname>B.</fname><surname>van Sures</surname>

fifth string

van Sures, B., to be tagged as <surname>van Sures</surname><fname>B.</fname>

sixth string

Bockris, O. M. J., to be tagged as <surname>Bockris</surname><mname>O.</mname> <mname>M.</mname><fname>J.</fname>

All 6 should be converted in a single regex.

Regards,
Ganesh






John W. Krahn wrote:

N. Ganesh Babu wrote:

Dear All,


Hello,

I have to convert these lines into individual part of name information with a single regular expression.

Input:
B. E. Conway,
J. O. M. Bockris
B. Conway

Output:
<fname>B.</fname><mname>E.</mname><surname>Conway</surname>
<fname>J.</fname><mname>O.</mname> <mname>M.</mname> <surname>Bockris</surname>
<fname>B.</fname> <surname>Conway</surname>


Can anybody help me in getting the single regular expression.



$ perl -le'
my @names = ( "B. E. Conway", "J. O. M. Bockris", "B. Conway" );
for my $name ( @names ) {
print $name;
$name =~ s!^(\S+)\s+((?:\S+\s+)*)(\S+)$!<fname>$1</fname>@{[map"<mname>$_</mname>",split" ",$2]}<surname>$3</surname>!;
print $name;
}
'
B. E. Conway
<fname>B.</fname><mname>E.</mname><surname>Conway</surname>
J. O. M. Bockris
<fname>J.</fname><mname>O.</mname> <mname>M.</mname><surname>Bockris</surname>
B. Conway
<fname>B.</fname><surname>Conway</surname>




John


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to