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. java中数据库和VO的一一对应关系

    如图所示,数据库中数据如果有下划线,则JavaVO中删除,除第一个单词外,其他单词首字母大写

  2. 一个故事讲懂vue父子组件传值

    作者:李佳明同学链接:https://www.jianshu.com/p/2272b6ca0f0c 一个故事讲懂vue父子组件传值 讲故事前先讲代码 父组件向子组件传值 父组件数据传递给子组件可以通过 ...

  3. egg 的学习

    1.初始化项目 快速生成项目: $ npm i egg-init -g $ egg-init egg-example --type=simple $ cd egg-example $ npm i 启动 ...

  4. win10 + VS2015 编译 ARPACK

    step 1: 下载ARPACK , mingw-w64-install 和 mingw-get-inst-20120426.exe: step 2: 安装 MinGW-64默认安装路径即可. ste ...

  5. VS2013+phread.h环境配置

    原文链接:http://blog.csdn.net/qianchenglenger/article/details/16907821 本人使用的是windows7 旗舰版64位 目前用的是pthrea ...

  6. python常用技巧 — 杂

    目录: 1. 找到字符串中的所有数字(python find digits in string) 2. python 生成连续的浮点数(如 0.1, 0.2, 0.3, 0.4, ... , 0.9) ...

  7. 在 IntelliJ IDEA 中这样使用 Git,效率提升2倍以上

    1.Git简介 Git是目前流行的分布式版本管理系统.它拥有两套版本库,本地库和远程库,在不进行合并和删除之类的操作时这两套版本库互不影响.也因此其近乎所有的操作都是本地执行,所以在断网的情况下任然可 ...

  8. 【Zookeekper】分布锁Curator

    有序节点:假如当前有一个父节点为/lock,我们可以在这个父节点下面创建子节点:zookeeper提供了一个可选的有序特性,例如我们可以创建子节点“/lock/node-”并且指明有序,那么zooke ...

  9. 【dart学习】-- Dart之async和await

    一,概述 在Dart1.9中加入了async和await关键字,有了这两个关键字,我们可以更简洁的编写异步代码,而不需要调用Future相关的API.他们允许你像写同步代码一样写异步代码和不需要使用F ...

  10. linux之-mysql数据库约束3

    在MySQL中,通常有这几种约束: DROP DATABASE mysql_shiyan;删除数据库 主键 (PRIMARY KEY)是用于约束表中的一行,作为这一行的唯一标识符,在一张表中通过主键就 ...