python re.I compile search
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的更多相关文章
- [LeetCode]题解(python):081 - Search in Rotated Sorted Array II
题目来源 https://leetcode.com/problems/search-in-rotated-sorted-array-ii/ Follow up for "Search in ...
- 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 ...
- python语法re.compile模块介绍
1. re模块是正则表达式模块,re模块中包含一个重要函数是compile(pattern [, flags]) ,该函数根据包含的正则表达式的字符串创建模式对象.可以实现更有效率的匹配. impor ...
- Learning Python 008 正则表达式-003 search()方法
Python 正则表达式 - search()方法 findall()方法在找到第一个匹配之后,还会继续找下去,findall吗,就是找到所有的匹配的意思.如果你只是想找到第一个匹配的信息后,就不在继 ...
- Python之exec()/compile()方法使用
# Python内置函数exec()可以用来执行Python代码 # 或内置函数compile()编译的代码对象 # exec程序中可写入python语法格式的代码,并直接输出. exec('prin ...
- [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 ...
- python 带正则的search 模块
glob 是python 提供的一个支持正则表达式的查找文件的模块. 实现上采用了os.listdir() 和 fnmatch.fnmatch(). 但是没有真的invoking a subshe ...
- Python eval,exac,compile
# eval 是把字符串类型的数据作为代码进行执行 s = "18+2" ret = eval(s) # 执行字符串类型的代码 print(ret) code = input(&q ...
- python eval, exec. compile
compile 编译某段代码, (将一个字符串编译为字节代码), 以方便重复调用. exec 可以理解为和if, for一样是一个语法声明, 而不是一个函数. 注意globals和locals的含义. ...
随机推荐
- 利用Navicat Premium连接Oracle数据库
利用Navicat Premium连接Oracle数据库 Navicat premium是一款数据库管理工具,支持多种数据库,也非常轻量: 安装包准备:Navicat Premium_11.1.8简体 ...
- shell使用reposync同步仓库
- mysql安装与修改密码
数据库基本概念:数据的仓库 数据库服务器-->数据库-->表-->记录-->属性(列,字段) unix下数据库服务安装: apt-get install -y mysql-se ...
- jQuery HTML-设置
例子1 html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> &l ...
- linux make: *** No targets specified and no makefile found. Stop.
[root@localhost Python-]# ./configure checking build system type... x86_64-unknown-linux-gnu checkin ...
- shell 读取文件的每一行
1.使用while #!/bin/bash while read line do echo $line done < file.txt #!/bin/bash cat file.txt | wh ...
- mysql添加索引和sql分析
mysql索引操作 查看索引 show indexes from students; #students为表名 mysql添加索引命令 创建索引 .PRIMARY KEY(主键索引) mysql> ...
- 【Windows、SVN】在Windows服务器下安装SVN,并在客户端能维护代码版本
1.分别在客户端和服务器端安装软件 在网上搜索一下安装包的下载地址(这里暂不介绍) 得到2个安装文件 Server是装在服务器端的,另外一个装在客户端 2.安装SVN服务器端 基本一致下一步即可 特殊 ...
- CDQ分治&整体二分学习个人小结
目录 小结 CDQ分治 二维LIS 第一道裸题 bzoj1176 Mokia bzoj3262 陌上花开 bzoj 1790 矩形藏宝地 hdu5126四维偏序 P3157 [CQOI2011]动态逆 ...
- php开发面试题---Redis和Memcache区别,优缺点对比
php开发面试题---Redis和Memcache区别,优缺点对比 一.总结 一句话总结: Redis相当于Memcache的扩展,增加比如持久化.多种数据结构.集群分布式功能 反思的回顾非常有用,因 ...