찾다

 >  Q&A  >  본문

python正则表达式

有一个字符串

1

= "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]"

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

1

2

3

4

5

6

7

("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]")


高洛峰高洛峰3052일 전971

모든 응답(3)나는 대답할 것이다

  • 三叔

    三叔2016-11-11 09:25:11

    1

    re.split(r'(\[[^a-zA-Z]+\])', s)

    简单但不严谨的答案


    회신하다
    0
  • 欧阳克

    欧阳克2016-11-11 09:24:55

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

    회신하다
    0
  • 三叔

    三叔2016-11-11 09:24:44

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

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    #!/usr/bin/python

    #-*- coding: UTF-8 -*-

    #author:zhaoyingnan

    import re;

    = "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], [12and spectroscopy [13]. Also,very directive optical antennas with electronically controlled ra-diation pattern are 

    the subject of great interest for applicationssuch as planar imaging [16and LIDAR [17]";

    listMatch_1 = re.findall('(?:\.|\,|and)\s([\w\s,-]+)([\[\d\]]+(?:–[\[\d\]]+|,\s[\[\d\]]+)?)', s, re.I);                                                 

    for in listMatch_1:

        print i;


    회신하다
    0
  • 취소회신하다