栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

正则表达式可在多种情况下匹配版权声明中的公司名称

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

正则表达式可在多种情况下匹配版权声明中的公司名称

您可以考虑使用正则表达式

(?i)(?:©(?:s*Copyright)?|Copyright(?:s*©)?)s*d+(?:s*-s*d+)?s*(.*?(?=W*Alls+rightss+reserved)|[^.]*(?=.)|.*)

请参阅regex演示。使用不区分大小写的修饰符

re.I

细节

  • (?:©(?:s*Copyright)?|Copyright(?:s*©)?)
    -要么
    • ©(?:s*Copyright)?
      -
      ©
      焦炭跟随以0+空格可选子,然后
      Copyright
    • |
      - 要么
    • Copyright(?:s*©)?
      -
      Copyright
      后跟0+空格和
      ©
      char的可选子字符串
  • s*
    -0+空格
  • d+
    -1个以上的数字(
    d{4}
    如果年份始终包含4个数字,则使用)
  • (?:s*-s*d+)?
    -
    -
    用0+空格和1+数字括起来的可选序列(
    d{4}
    如果年份始终包含4位数字,则使用)
  • s*
    -0+空格
  • (.*?(?=W*Alls+rightss+reserved)|[^.]*(?=.)|.*)
    - 捕获第1组 :以下任何一种方法:
    • .*?(?=W*Alls+rightss+reserved)
      -除换行符以外的任何0+个字符,尽可能少,最多0+个非单词字符,后跟
      All rights reserved
      字符串
    • [^.]*(?=.)
      -
      .
      尽可能多的0+个字符,
      .
      不包括在内
      .
    • .*
      -其余部分

Python演示:

import res = "Copyright © 2019 Apple Inc. All rights reserved.rn© 2019 Quid, Inc. All Rights Reserved.rn© 2009 Database Designs rn© 2019 Rediker Software, All Rights Reservedrn©2019 EVOSUS, INC. ALL RIGHTS RESERVEDrn© 2019 Walmart. All Rights Reserved.rn© Copyright 2003-2019 Exxon Mobil Corporation. All Rights Reserved.rnCopyright © 1978-2019 Berkshire Hathaway Inc.rn© 2019 McKesson Corporationrn© 2019 UnitedHealth Group. All rights reserved.rn© Copyright 1999 - 2019 CVS HealthrnCopyright 2019 General Motors. All Rights Reserved.rn© 2019 Ford Motor Companyrn©2019 AT&T Intellectual Property. All rights reserved.rn© 2019 GENERAL ELECTRICrnCopyright ©2019 AmerisourceBergen Corporation. All Rights Reserved.rn© 2019 Verizonrn© 2019 Fannie MaernCopyright © 2018 Jonas Construction Software Inc. All rights reserved.rnAll Comments © Copyright 2017 Kroger | The Kroger Co. All Rights Reservedrn© 2019 Express scripts Holding Company. All Rights Reserved. 1 Express Way, St. Louis, MO 63121rn© 2019 JPMorgan Chase & Co.rnCopyright © 1995 - 2018 Boeing. All Rights Reserved.rn© 2019 Bank of America Corporation. All rights reserved.rn© 1999 - 2019 Wells Fargo. All rights reserved. NMLSR ID 399801rn©2019 Cardinal Health. All rights reserved.rn© 2019 Quid, Inc All Rights Reserved."rx = r"(?:©(?:s*Copyright)?|Copyright(?:s*©)?)s*d+(?:s*-s*d+)?s*(.*?(?=W*Alls+rightss+reserved)|[^.n]*(?=.)|.*)"for m in re.findall(rx, s, re.I):    print(m)

输出:

Apple IncQuid, IncDatabase Designs Rediker SoftwareEVOSUS, INCWalmartExxon Mobil CorporationBerkshire Hathaway IncMcKesson CorporationUnitedHealth GroupCVS HealthGeneral MotorsFord Motor CompanyAT&T Intellectual PropertyGENERAL ELECTRICAmerisourceBergen CorporationVerizonFannie MaeJonas Construction Software IncKroger | The Kroger CoExpress scripts Holding CompanyJPMorgan Chase & CoBoeingBank of America CorporationWells FargoCardinal HealthQuid, Inc


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/372928.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号