import re
string = "The quick brown fox jumps over the lazy dog."
a_list = string.split()
pattern = re.compile(r'THE',re.I)

count = 0
for word in a_list:
if pattern.search(word):
count +=1
print(count)

替换方式1

string_to_find = r"the"
pattern = re.compile(string_to_find,re.I)
print(re.sub(pattern,"a",string))

替换方式2

string_to_find = r"the"
pattern = re.compile(string_to_find,re.I)
print(pattern.sub("a",string))

re.sub索引替换作用,替换方式1和替换方式2的作用是一样的。

python re.I compile search的更多相关文章

  1. [LeetCode]题解(python):081 - Search in Rotated Sorted Array II

    题目来源 https://leetcode.com/problems/search-in-rotated-sorted-array-ii/ Follow up for "Search in ...

  2. python JSON API duckduckgo search engine 使用duckduckgo API 尝试搜索引擎

    The duckduckgo.com's search engine is very neat to use. Acutally it has many things to do with other ...

  3. python语法re.compile模块介绍

    1. re模块是正则表达式模块,re模块中包含一个重要函数是compile(pattern [, flags]) ,该函数根据包含的正则表达式的字符串创建模式对象.可以实现更有效率的匹配. impor ...

  4. Learning Python 008 正则表达式-003 search()方法

    Python 正则表达式 - search()方法 findall()方法在找到第一个匹配之后,还会继续找下去,findall吗,就是找到所有的匹配的意思.如果你只是想找到第一个匹配的信息后,就不在继 ...

  5. Python之exec()/compile()方法使用

    # Python内置函数exec()可以用来执行Python代码 # 或内置函数compile()编译的代码对象 # exec程序中可写入python语法格式的代码,并直接输出. exec('prin ...

  6. [LeetCode&Python] Problem 704. Binary Search

    Given a sorted (in ascending order) integer array nums of n elements and a target value, write a fun ...

  7. python 带正则的search 模块

    glob  是python 提供的一个支持正则表达式的查找文件的模块. 实现上采用了os.listdir() 和 fnmatch.fnmatch().  但是没有真的invoking a subshe ...

  8. Python eval,exac,compile

    # eval 是把字符串类型的数据作为代码进行执行 s = "18+2" ret = eval(s) # 执行字符串类型的代码 print(ret) code = input(&q ...

  9. python eval, exec. compile

    compile 编译某段代码, (将一个字符串编译为字节代码), 以方便重复调用. exec 可以理解为和if, for一样是一个语法声明, 而不是一个函数. 注意globals和locals的含义. ...

随机推荐

  1. 微信小程序中new Date()转换时间时间格式时IOS不兼容的问题

    本周写小程序,遇到的一个bug,在chrome上显示得好好的时间,一到Safari/iPhone 就报错 “invalid date”,时间格式为“2019.06.06 13:12:49”,然后利用n ...

  2. CSS实现不换行/自动换行/文本超出隐藏显示省略号

    在写页面的时候,我们经常会需要用到关于文本的换行,强制换行以及显示几行超过显示省略号等,今天我们就对这些问题来做个汇总吧! 1.自动换行 div{ word-wrap:break-word; word ...

  3. jQuery查阅api手册

    原文&出处:jQuery API 3.3.1 速查表  --作者:Shifone http://jquery.cuishifeng.cn/

  4. bi包

    闭包是函数式编程的概念 闭包的定义:由函数极其封闭的自由变量组成的集合体. 其实每一个函数都是一个闭包 特点:函数中嵌套函数. 在返回的时候不仅返回函数本身,而且返回内部函数的值,关键词‘释放’ 闭包 ...

  5. css3 序列帧动画抖动

    页面需要一个动画,设计师给了动画的序列帧 项目由vue构建,使用css3做动画 html <div class="work_two_main"></div> ...

  6. I2C用户态驱动设计

    一.用户态驱动模型 1.1 I2C通用驱动代码 i2c_dev_init: static int __init i2c_dev_init(void) { int res; printk(KERN_IN ...

  7. Database基础(三):SQL数据导入/导出、 操作表记录、查询及匹配条件

    一.SQL数据导入/导出 目标: 使用SQL语句完成下列导出.导入操作: 将/etc/passwd文件导入userdb库userlist表并给每条记录加编号 将userdb库userlist表中UID ...

  8. Cisco基础(一):Vlan的划分、配置trunk中继链路、以太通道配置、DHCP服务配置

    一.Vlan的划分 目标: VLAN(虚拟局域网)是对连接到的第二层交换机端口的网络用户的逻辑分段,不受网络用户的物理位置限制而根据用户需求进行网络分段.一个VLAN可以在 一个交换机或者跨交换机实现 ...

  9. 跨主机网络-overlay(18)

    docker overlay跨主机网络 .环境 docker版本 Docker version -ce, build fc4de44 3台主机 192.168.55.51 host1 192.168. ...

  10. 汇编学习(1)——win7 64位调出debug

      一.安装方法: 1.下载一个dosbox和win7 32位debug.exe,安装dosbox,打开页面 2. 将debug.exe放入磁盘根目录,这里以D盘为例.在dosbox中输入mount ...