博客
关于我
【python】特定模式抽取字符串
阅读量:152 次
发布时间:2019-02-28

本文共 1625 字,大约阅读时间需要 5 分钟。

?????????????HTML????????????????Windows 7???Python 3.5.2??????????????

????<??>string<??>???????string???????????

import rep = re.compile(r'
(.*)
')matchp = p.search("
positive
")if matchp: print(matchp.group(1)) # ???? print(matchp.group(0)) # ?????

???????matchp.group(1) ???? "positive"?? matchp.group(0) ?????????

???????????


???????HTML????????????????????????

?????<??>string<??>???????string???????????

import rep = re.compile(r'
(.*)
')matchp = p.search("
positive
")if matchp: print(matchp.group(1)) # ???? print(matchp.group(0)) # ?????

???????matchp.group(1) ???? "positive"?? matchp.group(0) ?????????

???????????


?????

???????HTML???????????????????????????????????????????????????????

import rep = re.compile(r'
(.*)
')matchp = p.search("
positive
")if matchp: print(matchp.group(1)) # ???? print(matchp.group(0)) # ?????

?????

positive
positive

???

  • ??? matchp.group(1) ???? "positive"??????????????
  • ??? matchp.group(0) ????????????????????
  • ????????????????


    ?????

    ???????????????????????????????? .* ??????????????????????????HTML??????? <div> ???????????????????

    ????????????????

    import rep = re.compile(r'
    (.*?)
    ', re.DOTALL)matchp = p.search("
    positive
    ")if matchp: print(matchp.group(1)) # ??????????

    ????????? r'<polarity>(.*?)</polarity>' ??? re.DOTALL flag??? . ????????????????????????????????


    ???

    ??????????????????????????????????????????????????????

    转载地址:http://bszc.baihongyu.com/

    你可能感兴趣的文章
    OA项目之会议通知(查询&是否参会&反馈详情)
    查看>>
    Vue.js 学习总结(13)—— Vue3 version 计数介绍
    查看>>
    OA项目之我的会议(会议排座&送审)
    查看>>
    OA项目之我的会议(查询)
    查看>>
    OA项目之我的审批(会议查询&会议签字)
    查看>>
    OA项目之项目简介&会议发布
    查看>>
    ObjC的复制操作
    查看>>
    Object c将一个double值转换为时间格式
    查看>>
    object detection之Win10配置
    查看>>
    object detection训练自己数据
    查看>>
    object detection错误Message type "object_detection.protos.SsdFeatureExtractor" has no field named "bat
    查看>>
    object detection错误之Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
    查看>>
    object detection错误之no module named nets
    查看>>
    Object of type 'ndarray' is not JSON serializable
    查看>>
    Object Oriented Programming in JavaScript
    查看>>
    object references an unsaved transient instance - save the transient instance before flushing
    查看>>
    Object 类的常见方法有哪些?
    查看>>
    Object-c动态特性
    查看>>
    Object.assign用法
    查看>>
    Object.create
    查看>>