简体   繁体   中英

how to split the strings into first name and last name

The namelist is:

[J. A. Rubiño-Martín, R. Rebolo, M. Aguiar, R. Génova-Santos, F. Gómez-Reñasco, J. M. Herreros, R.J. Hoyland, C. López-Caraballo, A. E. Pelaez Santos, V. Sanchez de la Rosa] 

and I need to split it into

[[J. A.], [Rubiño-Martín], [R.], [Rebolo], [M.], [Aguiar], [R.], [Génova-Santos], [F.], [Gómez-Reñasco], [J. M.], [Herreros], [R.J.], [Hoyland], [C.], [López-Caraballo], [A. E.], [Pelaez Santos], [V.], [Sanchez de la Rosa] 

using python regex

For the given input, this regex works. The first group will match any number of tokens followed by a dot, multiple times in greedy fashion. The second group matches everything after the last dot followed by one ore more spaces.

^(.+\.)+\s+(.+)$

https://regex101.com/r/Jxy3Un/1

Here is a visualization :

正则表达式可视化

But as pointed out in the comments, it could easily break if you get names that don't follow this rather strict pattern.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM