python正则表达式
高洛峰
高洛峰 2016-11-11 09:24:15
[Python讨论组]

有一个字符串

s = "I. INTRODUCTIONIN analogy with the radio-frequency or microwave antennas,an optical antenna facilitates energy transfer from guided-wave modes of an optical waveguide to optical free-space modesand vice versa. Recently, optical antennas have received signif-icant attention due to their ability to control the light emissionwithin a nano-scale footprint [1]–[15]. Optical antennas have thecapability to boost the efficiency of photodetection [8], [9], sens-ing [10], heat transfer [11], [12] and spectroscopy [13]. Also,very directive optical antennas with electronically controlled ra-diation pattern are the subject of great interest for applicationssuch as planar imaging [16] and LIDAR [17]"

有没有办法把它分解类似下面的结果?

("Recently, optical antennas have received signif-icant attention due to their ability to control the light emissionwithin a nano-scale footprint.", "[1]–[15]")
("Optical antennas have thecapability to boost the efficiency of photodetection", "[8], [9]")
("sens-ing", "[10]")
("heat transfer", "[11], [12]")
("and spectroscopy", "[13]")
("Also,very directive optical antennas with electronically controlled ra-diation pattern are the subject of great interest for applicationssuch as planar imaging", "[16]")
("and LIDAR", "[17]")


高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

全部回复(3)
三叔
re.split(r'(\[[^a-zA-Z]+\])', s)

简单但不严谨的答案


欧阳克

这种规律性较差的,正则不如用 split 来得方便。

三叔

首先,你这字符串里面有个特殊字符fi,在efficiency这个单词里面,如果将其替换为fi的话,我下面的则可以使用.

#!/usr/bin/python
#-*- coding: UTF-8 -*-
#author:zhaoyingnan
import re;
s = "I. INTRODUCTIONIN analogy with the radio-frequency or microwave antennas,an optical antenna facilitates energy transfer from guided-wave modes of an
 optical waveguide to optical free-space modesand vice versa. Recently, optical antennas have received signif-icant attention due to their ability to con
trol the light emissionwithin a nano-scale footprint [1]–[15]. Optical antennas have thecapability to boost the efficiency of photodetection [8], [9], s
ens-ing [10], heat transfer [11], [12] and spectroscopy [13]. Also,very directive optical antennas with electronically controlled ra-diation pattern are 
the subject of great interest for applicationssuch as planar imaging [16] and LIDAR [17]";
listMatch_1 = re.findall('(?:\.|\,|and)\s([\w\s,-]+)([\[\d\]]+(?:–[\[\d\]]+|,\s[\[\d\]]+)?)', s, re.I);                                                 
for i in listMatch_1:
    print i;


热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号